Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
try
            {
                DataSet ds=new DataSet();
                connection.Open();
                cmd = new SqlCommand();
                cmd.Connection = connection;
                dadapter = new SqlDataAdapter();
                dadapter.InsertCommand= connection.CreateCommand();
                dadapter.InsertCommand.CommandText = "insert into contacts (CName,CNumber,Address) values(@CName,@Number,@Address)";
                cmd.Parameters.AddWithValue("@CName", textBox1.Text);
                cmd.Parameters.AddWithValue("@CNumber",textBox2.Text);
                cmd.Parameters.AddWithValue("@Address",textBox3.Text);
            
                MessageBox.Show("Record Saved", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

it's executed successfully but new record can't add to the database.
What's the problem here?
Posted
Updated 6-Jan-13 2:39am
v2

1 solution

It is executing? I doubt!
You have missed to execute it using ExecuteNonQuery[^] before showing your confirmation dialog.
 
Share this answer
 
Comments
Noor Nawaz 6-Jan-13 6:26am    
Will you please tell me, where to put this statement?
Zoltán Zörgő 6-Jan-13 6:28am    
After all parameters are set.
Noor Nawaz 6-Jan-13 9:06am    
Thanks A lot. I've done it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900