Adding Database Records

来源:互联网 发布:淘宝hd 5.0.1 ios 编辑:程序博客网 时间:2024/05/29 19:13

Explanation:Add to the database record after When a user registration

string name = txtUserName.Text.Trim();        string pwd = txtPwd.Text.Trim();        string conStr = "Data Source=~;Initial Catalog=web;Integrated Security=True";        string strsql = "select * from tb_user";        SqlConnection conn = new SqlConnection(conStr);        conn.Open();        SqlDataAdapter da = new SqlDataAdapter();        da.SelectCommand = new SqlCommand(strsql, conn);        SqlCommandBuilder scb = new SqlCommandBuilder(da);        DataSet ds = new DataSet();        da.Fill(ds);        int i=ds.Tables[0].Rows.Count;        DataRow newRow = ds.Tables[0].NewRow();        newRow["ID"] = ds.Tables[0].Rows.Count + 1;        newRow["username"] = txtUserName.Text.Trim();        newRow["password"] = txtPwd.Text.Trim();        newRow["jurisdiction"] = "1";        ds.Tables[0].Rows.Add(newRow);        da.Update(ds);        conn.Close();


                                             
0 0