.net实现信息增删改查的小例子

来源:百度知道 编辑:UC知道 时间:2024/07/02 19:40:09
public void Delete(object source,DataGridCommandEventArgs e)
{
string strname=((TextBox)e.Item.Cells[0].Controls[0]).Text;
DataTable dt =Biz.manage.delone(strname);

this.allxx.DataSource = dt.DefaultView;
this.allxx.DataBind();
}

/// <summary>
/// 删除员工信息
/// </summary>
public static DataTable delone(string name)
{
DataTable dt = new DataTable();

using(SqlConnection conn = new SqlConnection(connectionString))//使用using,退出有效范围后自动释放
{
using(SqlCommand command = new SqlCommand())
{
command.CommandType = CommandType.Text ;
command.CommandText = "delete from yg where name='"+name+"'"

你可以看下这里:

http://dev.csdn.net/article/51/51377.shtm

你的代码有问题
不多说 给你代码
----删除
SqlConnection conn = new SqlConnection(connectionString)
string sql = "delete from yg where name='"+name+"'";
conn.Open();
SqlCommand command = new SqlCommand(sql,conn)
int i=0;
i=com.ExecuteNonQuery();
if(i>0)
{
删除成功
}
---更新---修改sql语句就OK
---

我看到的是删除的方法
更新哪来的?