there are many posts about this, but no one helped me. Maybe i have just a logical problem or something like this. I'am a C# newbie.
So following problem. I have a dataGridView in Form1. When i click button1 Form6 appears, i give in a table name and fillDataGrid-mehtod runs in Form1. But. shows no Data the dataGradview just keeps empty with nothing in it.
Now the curios thing, if i place the Code from fillDataGrid-method in the button1 method every thing works fine.
Database (SQLite) connection works fine (not shown in the code example).
FORM1:
private void button1_Click(object sender, EventArgs e)
{
Form6 f6 = new Form6();
f6.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Form3 createTable = new Form3();
createTable.Show();
}
public void fillDataGrid(String Eingabe)
{
String tabelle = Eingabe;
String selectCommand = "select ID, VON, BIS, DAUER, KOMMENTAR from " + tabelle + ";";
SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(selectCommand, sqlite_conn);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
//dataGridView1.DataBindings.Clear();
//dataGridView1.Columns.Clear();
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
FORM6:
private void button1_Click(object sender, EventArgs e)
{
Form1 f1 = new Form1();
String Eingabe = textBox5.Text;
f1.fillDataGrid(Eingabe);
Hide();
}
Aucun commentaire:
Enregistrer un commentaire