hello,
how i can to refresh datagridview after insert to the database , ( in every time click on the button , the Previous record only that appear in the grid view not the Current)
private void button2_Click(object sender, EventArgs e)
{
string JSS_connetionString001 = null;
OleDbConnection JSS_cnn001;
OleDbCommand JSS_cmd001;
string JSS_sql001 = null;
OleDbDataReader JSS_reader001;
JSS_connetionString001 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/je_salestoredb.mdb;Persist Security Info=True;Jet OLEDB:Database Password=JE2014";
JSS_sql001 = "select * from employees where employee_ID=(select max(employee_ID) from employees)";
JSS_cnn001 = new OleDbConnection(JSS_connetionString001);
try
{
JSS_cnn001.Open();
JSS_cmd001 = new OleDbCommand(JSS_sql001, JSS_cnn001);
JSS_reader001 = JSS_cmd001.ExecuteReader();
while (JSS_reader001.Read())
{
label01.Text = (JSS_reader001.GetValue(0) + "");
}
JSS_reader001.Close();
JSS_cmd001.Dispose();
JSS_cnn001.Close();
}
catch (Exception ex)
{
return;
}
if (label01.Text == "")
{
label01.Text = "0000001";
}
else
{
double JSS_prductG_ID = System.Convert.ToDouble(label01.Text) + 0000001;
label01.Text = JSS_prductG_ID.ToString("0000000");
}
string JSS_connetionString002 = null;
OleDbConnection JSS_connection002;
OleDbDataAdapter JSS_oledbAdapter002 = new OleDbDataAdapter();
string JSS_sql002 = null;
JSS_connetionString002 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/je_salestoredb.mdb;Persist Security Info=True;Jet OLEDB:Database Password=JE2014";
JSS_connection002 = new OleDbConnection(JSS_connetionString002);
JSS_sql002 = "insert into employees(employee_ID,employee_CODE,employee_NAME,employee_NATIONAL_CODE,employee_CITY,employee_STATE,employee_VILLAGE,employee_TEL1,employee_TEL2,employee_EMAIL,employee_SALARY,employee_WORK,employee_SYSTEM_Authority,employee_PASS,employee_JOIN_DATE,employee_EDIT_DATE,employee_USER) values('" + label01.Text + "','" + textbox02.Text + "','" + textbox03.Text + "','" + textbox04.Text + "','" + textbox05.Text + "','" + textbox06.Text + "','" + textbox07.Text + "','" + textbox08.Text + "','" + textbox09.Text + "','" + textbox10.Text + "','" + textbox11.Text + "','" + textbox12.Text + "','" + label13.Text + "','" + textbox14.Text + "','" + textbox15.Text + "','" + textbox16.Text + "','" + label17.Text + "')";
try
{
JSS_connection002.Open();
JSS_oledbAdapter002.InsertCommand = new OleDbCommand(JSS_sql002, JSS_connection002);
JSS_oledbAdapter002.InsertCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
return;
}
employeesDataGridView.Refresh();
string JSS_connetionString011 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/je_salestoredb.mdb;Persist Security Info=True;Jet OLEDB:Database Password=JE2014";
string JSS_sql011 = "select * from employees";
OleDbConnection JSS_connection011 = new OleDbConnection(JSS_connetionString011);
OleDbDataAdapter JSS_dataadapter011 = new OleDbDataAdapter(JSS_sql011, JSS_connection011);
DataSet JSS_ds011 = new DataSet();
JSS_ds011.Clear();
try
{
JSS_connection011.Open();
JSS_dataadapter011.Fill(JSS_ds011, "employees");
JSS_connection011.Close();
employeesDataGridView.DataSource = JSS_ds011;
employeesDataGridView.DataMember = "employees";
}
catch (Exception ex)
{
return;
}
employeesDataGridView.Refresh();
}
this code don't work
but by used two button is work will
private void button2_Click(object sender, EventArgs e)
{
string JSS_connetionString001 = null;
OleDbConnection JSS_cnn001;
OleDbCommand JSS_cmd001;
string JSS_sql001 = null;
OleDbDataReader JSS_reader001;
JSS_connetionString001 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/je_salestoredb.mdb;Persist Security Info=True;Jet OLEDB:Database Password=JE2014";
JSS_sql001 = "select * from employees where employee_ID=(select max(employee_ID) from employees)";
JSS_cnn001 = new OleDbConnection(JSS_connetionString001);
try
{
JSS_cnn001.Open();
JSS_cmd001 = new OleDbCommand(JSS_sql001, JSS_cnn001);
JSS_reader001 = JSS_cmd001.ExecuteReader();
while (JSS_reader001.Read())
{
label01.Text = (JSS_reader001.GetValue(0) + "");
}
JSS_reader001.Close();
JSS_cmd001.Dispose();
JSS_cnn001.Close();
}
catch (Exception ex)
{
return;
}
if (label01.Text == "")
{
label01.Text = "0000001";
}
else
{
double JSS_prductG_ID = System.Convert.ToDouble(label01.Text) + 0000001;
label01.Text = JSS_prductG_ID.ToString("0000000");
}
string JSS_connetionString002 = null;
OleDbConnection JSS_connection002;
OleDbDataAdapter JSS_oledbAdapter002 = new OleDbDataAdapter();
string JSS_sql002 = null;
JSS_connetionString002 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/je_salestoredb.mdb;Persist Security Info=True;Jet OLEDB:Database Password=JE2014";
JSS_connection002 = new OleDbConnection(JSS_connetionString002);
JSS_sql002 = "insert into employees(employee_ID,employee_CODE,employee_NAME,employee_NATIONAL_CODE,employee_CITY,employee_STATE,employee_VILLAGE,employee_TEL1,employee_TEL2,employee_EMAIL,employee_SALARY,employee_WORK,employee_SYSTEM_Authority,employee_PASS,employee_JOIN_DATE,employee_EDIT_DATE,employee_USER) values('" + label01.Text + "','" + textbox02.Text + "','" + textbox03.Text + "','" + textbox04.Text + "','" + textbox05.Text + "','" + textbox06.Text + "','" + textbox07.Text + "','" + textbox08.Text + "','" + textbox09.Text + "','" + textbox10.Text + "','" + textbox11.Text + "','" + textbox12.Text + "','" + label13.Text + "','" + textbox14.Text + "','" + textbox15.Text + "','" + textbox16.Text + "','" + label17.Text + "')";
try
{
JSS_connection002.Open();
JSS_oledbAdapter002.InsertCommand = new OleDbCommand(JSS_sql002, JSS_connection002);
JSS_oledbAdapter002.InsertCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
return;
}
}
private void button3_Click(object sender, EventArgs e)
{
employeesDataGridView.Refresh();
string JSS_connetionString011 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/je_salestoredb.mdb;Persist Security Info=True;Jet OLEDB:Database Password=JE2014";
string JSS_sql011 = "select * from employees";
OleDbConnection JSS_connection011 = new OleDbConnection(JSS_connetionString011);
OleDbDataAdapter JSS_dataadapter011 = new OleDbDataAdapter(JSS_sql011, JSS_connection011);
DataSet JSS_ds011 = new DataSet();
JSS_ds011.Clear();
try
{
JSS_connection011.Open();
JSS_dataadapter011.Fill(JSS_ds011, "employees");
JSS_connection011.Close();
employeesDataGridView.DataSource = JSS_ds011;
employeesDataGridView.DataMember = "employees";
}
catch (Exception ex)
{
return;
}
employeesDataGridView.Refresh();
}
other detials
the first code make refresh to data grid veiw, but after pressing the button twice and don't show the current input but it works well if it is put in a separate button Event,and the table flashed (show the new value and disappear quickly and does not show except in the next time)