您的位置:首页 > 数据库

ADO.NET操作数据库(删除)

2013-01-22 14:53 267 查看
Default.aspx.cs中ADO.NET操作数据库(删除):
using System;using System.Collections.Generic;using System.Data;using System.Data.SqlClient;//添加ADO.net数据命名空间;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string strsql = "Data Source=(local);Initial Catalog=GustBook;User ID=sa;Password=sql2008@"; SqlConnection conn= new SqlConnection(strsql); try { Label1.Text = "数据库连接成功"; conn.Open(); string deleteQuery = "delete from tbGuestBook where id=1"; //上行删除表中id=1的一行内容; SqlCommand sqlcommand = new SqlCommand(deleteQuery, conn); //初始化command对象; sqlcommand.ExecuteNonQuery();//使用command方法; Label1.Text = "数据库删除成功"; } catch(Exception aa) { Label1.Text = aa.ToString(); } }}本文出自 “Jessen Liu的博文” 博客,请务必保留此出处http://zkhylt.blog.51cto.com/3638719/1123967
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: