John

John

  • NA
  • 43
  • 26k

How to update listbox after inserting new row

Dec 12 2010 12:41 PM
HI all

Im trying to get my from to insert new information into a database and display it. right now the information inputted goes into the database file. but the lstbox i have on my form displaying the current records doesnt get updated.

here is the coding for the button:

string dbconnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + @"data source=Book.mdb";
            OleDbConnection con = new OleDbConnection(dbconnection);
            OleDbCommand cmd = new OleDbCommand("INSERT INTO Books(BookKey,Title,Pages,AuthorKey,PublisherID) VALUES (?,?,?,?,?)", con);

            cmd.Parameters.Add("@BookKey", OleDbType.VarChar, 50, "BookKey").Value = textBox1.Text;
            cmd.Parameters.Add("@Title", OleDbType.VarChar).Value = textBox2.Text;
            cmd.Parameters.Add("@Pages", OleDbType.VarChar).Value = textBox3.Text;
            cmd.Parameters.Add("@AuthorKey", OleDbType.VarChar).Value = textBox4.Text;
            cmd.Parameters.Add("@PubliherID", OleDbType.VarChar).Value = textBox5.Text;

            con.Open();
            cmd.Connection = con;
            cmd.ExecuteNonQuery();
            con.Close();

            refreshlist();
 Hope someone can help

Regards

Answers (15)