public static SqlConnection connStr = new SqlConnection("server=127.0.0.1;uid=sa;pwd=sa;database=用户数据库");
private void addbutton1_Click(object sender, EventArgs e)
{
string selestr = "";
selestr = "select top 1 * from UserTable order by ID desc";
if (selestr.Trim() != "")
{
try
{
SqlDataAdapter da = new SqlDataAdapter(selestr, connStr);
DataSet ds = new DataSet();
da.Fill(ds, "newTable");
int Temip = 1;
if (ds.Tables["newTable"].Rows.Count == 1)
{ Temip = int.Parse(ds.Tables["newTable"].Rows[0]["ID"].ToString()) + 1; }
DataRow newdr = ds.Tables["newTable"].NewRow();
newdr["ID"] = Temip;
newdr["账号"] = textBox1.Text;
newdr["密码"] = textBox2.Text;
ds.Tables["newTable"].Rows.Add(newdr);
da.Update(ds,"newTable");
MessageBox.Show("添加成功");
}
catch (Exception)
{ MessageBox.Show("失败"); }
}}
请问,我上面的语句怎么不能向数据库中添加数据啊!错在什么地方?