Imam i sledecu verziju, ali dobijam gresku:
Value cannot be null.
Parameter name: dataTable
Code:
private void button4_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\busic.mdb";
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Select * from " + label1.Text + "", con);
BindingSource bindingSource1 = new BindingSource();
bindingSource1.DataMember = label1.Text;
DataTable dt = ds.Tables[0];
dt.TableName = textBox1.Text;
bindingSource1.DataSource = dt;//dataGridView1.DataSource;
bindingNavigator1.BindingSource = bindingSource1;
this.bindingSource1.EndEdit();
da.Update(ds.Tables["dt"]);
con.Close();
}
bazu (nazive tabela iz baze) izlistavam u liistBox ovako:
Code:
System.IO.File.Copy("c:\\baza.mdb", "c:\\kopija.mdb", true); //e.Extract(TargetDirectory, true); // overwrite == true
// Microsoft Access provider factory
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
DataTable userTables = null;
using (DbConnection connection = factory.CreateConnection())
{
// c:\test\test.mdb
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\kopija.mdb";
// We only want user tables, not system tables
string[] restrictions = new string[4];
restrictions[3] = "Table";
connection.Open();
// Get list of user tables
userTables = connection.GetSchema("Tables", restrictions);
connection.Close();
connection.Dispose();
}
// Add list of table names to listBox
for (int i = 0; i < userTables.Rows.Count; i++)
lbLinije.Items.Add(userTables.Rows[i][2].ToString());
dataGridView punim izabranom tabelom ovako:
Code:
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\busic.mdb";
OleDbDataAdapter da = new OleDbDataAdapter("Select * from " + label1.Text + "", con);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
column.SortMode = DataGridViewColumnSortMode.NotSortable;
}
BindingSource bindingSource1 = new BindingSource();
bindingSource1.DataMember = label1.Text;
bindingSource1.DataSource = ds.Tables[0];
// bindingSource1.DataSource= dataGridView1.DataSource;
bindingNavigator1.BindingSource = bindingSource1;
}
Don't panic!