Click here to Skip to main content
16,020,984 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello all, I am a newbie in programming and I have come across a problem that searches on the web hasn't yet presented me with a solution. I am able to save a new record to a database but I will have to restart the application in order to view the new entry. Below is the code that I use to send the record to the database. Any help is highly appreciated.

C#
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection("Data Source=ACER-SVR;Initial Catalog=ISL;Integrated Security=True");

private void button1_Click(object sender, EventArgs e)
{
    string select = "Select * from isltb";
    SqlDataAdapter da = new SqlDataAdapter(select, con);
    SqlCommand insert = new SqlCommand("_insert", con);

    insert.CommandType=CommandType.StoredProcedure;             
    insert.Parameters.Add("@com", SqlDbType.NVarChar).Value = textBox1.Text;
    insert.Parameters.Add("conper", SqlDbType.Text).Value = textBox5.Text;
    insert.Parameters.Add("@desig", SqlDbType.Text).Value = textBox6.Text;
    insert.Parameters.Add("@tel", SqlDbType.Int).Value= int.Parse(textBox4.Text);
    insert.Parameters.Add("@mob", SqlDbType.Int).Value= int.Parse(textBox7.Text);
    insert.Parameters.Add("@addr", SqlDbType.NVarChar).Value= textBox8.Text;
    insert.Parameters.Add("@email", SqlDbType.NVarChar).Value = textBox9.Text;

    con.Open();           
    insert.ExecuteNonQuery();            
    MessageBox.Show("...SUCCESS...");
    da.Fill(ds, "isltb");            
    con.Close();
}
Posted
Updated 25-Aug-10 2:44am
v3
Comments
Nish Nishant 25-Aug-10 8:46am    
Are you sure the insert is working as expected? You haven't applied the @ prefix to the conper parameter (in the code snippet you posted).
Ondeda 25-Aug-10 8:52am    
Thanx for the corection
Nish Nishant 25-Aug-10 8:53am    
So, did fixing that solve your problem?
Ondeda 25-Aug-10 8:58am    
Not yet, I still have to reload.
Nish Nishant 25-Aug-10 9:38am    
You probably need to reset your dataset (on your display control, most likely a grid).

1 solution

So what have you tried in order to "view the new entry"?

All you have to do is create a query that retrieves it from the database.
 
Share this answer
 
Comments
Nish Nishant 25-Aug-10 8:43am    
He's doing it already. He calls Fill on the data adapter passing in the select query string.
Ondeda 25-Aug-10 8:46am    
I am using navigation buttons on a Parent form to view the entries that i have entered. Only records entered before the application restart are shown.

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