1
Answer

How to insert records into table in database by using asp.net with c#.net?

paparao

paparao

17y
2.9k
1
HI Frens, I have taken two text textboxs and one button as well as i have created one table with two fields.Now i want to insert records into backend table. Then i have written some code,but it didn't show any exception.however, data didn't insert into table. can anybody rectify my code? string connstring = "server=paparao;uid=sa;pwd=sa;database=training"; SqlConnection cnPrintegra = new SqlConnection(); DataSet dsPrintegra = new DataSet(); cnPrintegra.ConnectionString = connstring; cnPrintegra.Open(); SqlDataAdapter cmdUsers = new SqlDataAdapter("select * from example", cnPrintegra); SqlCommandBuilder cmdb = new SqlCommandBuilder(cmdUsers); cmdUsers.Fill(dsPrintegra, "example"); DataRow cRow ; cRow = dsPrintegra.Tables["example"].NewRow(); cRow[0] = TextBox1.Text; cRow[1] = TextBox2.Text; dsPrintegra.Tables["example"].Rows.Add(cRow); dsPrintegra.AcceptChanges(); cmdUsers.Update(dsPrintegra, "example"); cnPrintegra.Close();
Answers (1)