刷新数据库的数据

时间:2010-06-16 13:11:48

标签: c# database winforms ms-access refresh

如何使用Windows窗体应用程序在c#中刷新数据库中的数据(ms访问)?我插入数据的部分代码:

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 (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();
    }
}

1 个答案:

答案 0 :(得分:0)

在执行insertCommand.ExecuteNonQuery()之后,立即绑定数据库中的数据。不知道你想再次填充什么。

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();
}