dataset数据集,实现添加数据不能插入。请高人指点。
using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
// SqlDataAdapter sda = new SqlDataAdapter("select * from users where uname=@uname and upwd=@upwd",conn);
// sda.SelectCommand.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
// //sda.SelectCommand.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
// sda.SelectCommand.Parameters.Add("@upwd", "test");
// sda.SelectCommand.Parameters["@uname"].Value = "test";
//// sda.SelectCommand.Parameters["@upwd"].Value = "test";
// DataSet ds = new DataSet();
// sda.Fill(ds);
// Response.Write(ds.Tables[0].Rows.Count);
}
protected void Button2_Click(object sender, EventArgs e)
{
DBHelper.ExecuteCommand("insert into users(uname,upwd) values('dd','dd')");
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlParameter[] sql = new SqlParameter[2];
sql[0] = new SqlParameter("@uname", SqlDbType.VarChar, 50, "uname");
sql[1] = new SqlParameter("@upwd", SqlDbType.VarChar, 20, "upwd");
sql[0].Value = "qq";
sql[1].Value = "qq";
DBHelper.ExecuteCommand("insert into users(uname,upwd) values(@uname,@upwd)",sql);
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter();
SqlConnection conn = new SqlConnection("uid=sa;pwd=11;data source=.;database=gwdb");
SqlCommand select = new SqlCommand("select * from users", conn);
sda.SelectCommand = select;
SqlCommand insert=new SqlCommand("insert into users(uname,upwd) values(@uname,@upwd)",conn);
insert.Parameters.Add("@uname", SqlDbType.VarChar, 50, "uname");
insert.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
insert.Parameters["@uname"].Value = "dog";
insert.Parameters["@upwd"].Value= "dog";
sda.InsertCommand = insert;
SqlCommand update = new SqlCommand("update users set upwd=@upwd",conn);
update.Parameters.Add("@upwd", SqlDbType.VarChar, 20, "upwd");
sda.UpdateCommand = update;
SqlCommand delete = new SqlCommand("delete from users where uid=@id",conn);
delete.Parameters.Add("@id", SqlDbType.Int, 4, "uid");
sda.DeleteComm