I have some textbox on my windows form. I want to insert those textbox value into a database table and show the updated table into a gridview when a button clicked. Here is my Insert code behind the button click event.
string connectionstring = ConfigurationManager.ConnectionStrings["myDBconn"].ToString();
SqlConnection objconnection = new SqlConnection(connectionstring);
objconnection.Open();
string strInsertCommand= "INSERT INTO party ( party_name, party_mobile, updated_at) VALUES( '" + txtAddPartyName.Text + "', '" + txtAddPartyMobile.Text + "', '" + DateTime.Now.ToShortDateString() + "')";
SqlCommand objCommand = new SqlCommand(strInsertCommand, objconnection);
objCommand.ExecuteNonQuery();
objconnection.Close();
And here is my gridview update code.
objconnection.Open();
objCommand = new SqlCommand("Select * from party", objconnection);
DataSet objDataset = new DataSet();
SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
objAdapter.Fill(objDataset);
dataGridView1.DataSource = objDataset.Tables[0];
objconnection.Close();
Problem is when I fill all textbox and hit the insert button then everything is work fine and datagridview also shows newly entered entry but database table does not updated with the new entry. There is no error message given at button click.
Thanks in advance, your help is greatly appreciated.
Sazzad