Refresh database's data
How can I refresh the data from my database (ms access) in c# using windows form application? Part of the code where I insert the data:
insertCommand.Parameters.Add("@ID_uporabnika", OleDbType.Integer).Value = Convert.ToInt32(textBox6.Text);
insertCommand.Parameters.Add("@datum", OleDbType.DBDate).Value = DateTime.Now.ToShortDateString();
insertCommand.Parameters.Add("@ID_zivila", OleDbType.Integer).Value = Convert.ToInt32(iDTextBox.Text);
insertCommand.Parameters.Add("@skupaj_kalorij", OleDbType.Double).Value = Convert.ToDouble(textBox1.Text);
empConnection.Open();
try
{
int count = insertCommand.ExecuteNonQuery();
}
catch (OleDb开发者_如何学GoException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
empConnection.Close();
MessageBox.Show("zauižiti obrok je bil shranjen");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
}
right after you do the insertCommand.ExecuteNonQuery(), bind the data from the database. not sure what you want to populate again though.
try
{
int count = insertCommand.ExecuteNonQuery();
// do your getting of data here
// use datareaders to populate your objects
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
empConnection.Close();
MessageBox.Show("zauižiti obrok je bil shranjen");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
精彩评论