SqlDataAdapter的四个COMMAND属性

作者在 2007-05-09 22:56:00 发布以下内容

1、使用存储过程:

(1)存储过程

create procedure InsertCommand @userName nvarchar(20),@userPwd nvarchar(20),@userAddress nvarchar(100)
as
begin
insert into dbUsers values(@userName,@userPwd,@userAddress)
end

(2)代码

  private void Button3_Click(object sender, System.EventArgs e)
  {
   SqlConnection con=new SqlConnection("server=.;uid=sa;pwd=lhd;database=dbNews");
   con.Open();
   SqlDataAdapter sda=new SqlDataAdapter();
   sda.InsertCommand=new SqlCommand("InserCommand",con);
   sda.InsertCommand.CommandType=CommandType.StoredProcedure;
   sda.InsertCommand.Parameters.Add("@userName","newName");
   sda.InsertCommand.Parameters.Add("@userPwd","newName");
   sda.InsertCommand.Parameters.Add("@userAddress","newAddress");
   sda.InsertCommand.ExecuteNonQuery();
   sda.SelectCommand=new SqlCommand("select * from dbUsers",con);
   sda.Fill(ds,"dbUsers");
   this.DataGrid1.DataSource=ds.Tables["dbUsers"];
   this.DataGrid1.DataBind();
   con.Close();
  }

2、deleteCommand

http://blog.csdn.net/ifan_net/archive/2006/11/10/1378466.aspx

3、

ASP.NET | 阅读 3285 次
文章评论,共0条
游客请输入验证码
浏览77888次