Hello!
1) How to get the number of tables in the database? Their names? And how to work with them in the general case?
For example, when I run an application, I want to get a list of tables in the database, and then click on one of the values to open the table.
At this stage, I work like this:
private void Form1_Load(object sender, EventArgs e) { OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Склад.mdb"); connection.Open(); OleDbCommand command = connection.CreateCommand(); command.CommandText = "SELECT * FROM Товары"; OleDbDataAdapter dataAdapter = new OleDbDataAdapter(); dataAdapter.SelectCommand = command; DataSet ds = new DataSet(); dataAdapter.Fill(ds); dataGridView1.DataSource = ds.Tables[0].DefaultView; connection.Close(); } It is clear that I display one table Goods.
How for example to refer to a particular table? Get the names of its columns, their type, etc.? ... This is especially necessary when creating a form for recording data ...
2) Something happened. Through a server browser, I created a connection to my database, and I had an object of type DataSet. Next, after working with him, I achieved the following:
private void Form1_Load(object sender, EventArgs e) { Sklad mySklad = new Sklad(); //MessageBox.Show("Число таблиц в БД "+mySklad.Tables.Count.ToString()); foreach (DataTable dt in mySklad.Tables) { DataGridView dtGrid = new DataGridView(); tabControl1.TabPages.Add(dt.TableName); dtGrid.Parent = tabControl1.TabPages[tabControl1.TabPages.Count-1]; dtGrid.Dock = DockStyle.Fill; dtGrid.Name = "Table_" + dt.TableName; dtGrid.DataSource = dt.DefaultView; dtGrid.Show(); } } But, the tables are empty. Where did the data go? Or how to get them out? I understand that it is necessary through request, but how to interact through request with this object DataSet ...
Thank!