SqlConnection str = new SqlConnection("server=127.0.0.1;uid=sa;pwd=sa;database=用户数据库");
SqlDataAdapter da = new SqlDataAdapter("select * from UserTable", str);
DataSet ds = new DataSet();
ds.Clear();
da.Fill(ds, "UserTable");
DataTable dt = ds.Tables["UserTable"];
DataRow newdr = dt.NewRow();//新建一行
newdr["账号"] = zhtextBox1.Text;
newdr["密码"] = mmtextBox2.Text;
dt.Rows.Add(newdr);//添加到行中
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(ds, "UserTable");
MessageBox.Show("恭喜您!注册成功", "消息框");
this.Close();
我想知道这样能将信息添加到数据库中吗?我调试时说不能添加。急想知道!