有什么方法可以在不关闭应用程序并再次打开它的情况下刷新网格视图?我正在尝试以这种方式刷新网格视图。
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.Parent.Refresh();
}
我以这种方式插入Access 数据库,
private void button2_Click(object sender, EventArgs e)
{
//Setting up Connection String
string connectionString1 = GetConnectionString();
OleDbConnection myConnection1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\\Users\\Daffodils\\Documents\\WindowsFormsApplication11\\WindowsFormsApplication11\\WindowsFormsApplication11\\PersonDatabase.mdb");
//OleDbConnection myConnection1 = new OleDbConnection(connectionString1);
String insertString = "Insert Into PersonTable([FirstName],[LastName],[City],[Age]) Values ('" + "John" + "','" + "Gray" + "','" + "Toronto" + "','" + "50" + "')";
using (myConnection1)
{
OleDbCommand command = myConnection1.CreateCommand();
command.CommandText = insertString;
try
{
// openning a connection to the database / table
myConnection1.Open();
//// SQL commnd class
OleDbDataReader myDataReader1 = command.ExecuteReader(); // exists as a part of SQL command class
//Closing Database connection
myDataReader1.Close();
//Console.WriteLine("Data was added to the table !!!");
MessageBox.Show("Data was added to the table !!!");
}
// dealing with exceptions
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//Console.WriteLine(ex.Message); // printing exception message to default output
}
}
}
我尝试过使用,dataGridView1.EndEdit();
但我仍然必须关闭应用程序并再次打开它。