日期:2014-05-18  浏览次数:20787 次

DataGridView中的数据在新增数据后如何刷新呢——这样就可以看到这个新增的数据了
这些代码写在窗体的按钮的事件处理程序中
private   void   button3_Click(object   sender,   EventArgs   e)
{
try
                        {
                               
                                string   temp   =   "insert   into   [user]   ([username],   [password],   [email])   values   ( 'a ', 'b ', 'c ')   ";
                                this.oleDbConnectionTest.ConnectionString   =   this.mycon;
                                this.oleDbConnectionTest.Open();
                                MessageBox.Show(temp);
                                oleDbCommandTest.CommandType   =   CommandType.Text;
                                oleDbCommandTest.CommandText   =   temp;
                                oleDbCommandTest.Connection   =   oleDbConnectionTest;
                                oleDbDataAdapterTest.InsertCommand   =   oleDbCommandTest;
                                oleDbDataAdapterTest.InsertCommand.ExecuteNonQuery();
                                oleDbDataAdapterTest.Fill(this.DataSetTest);
                                ///刷新的代码,我不会写。谢谢。
                                this.oleDbConnectionTest.Close();
                        }
                        catch   (Exception   ee)
                        {
                                MessageBox.Show(ee.ToString());
                        }
}

------解决方案--------------------
DataBind().......
------解决方案--------------------
this.datagrid1.datasouce = DataSetTest; //你的數據集