Situation:
Hello! I am trying to populate a WPF DataGrid toolkit with an MS Access database.
Here is what I have right now (it works):
//Load the datagrid with the database private void LoadDataGrid(string filename, string path) { string databaseConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + path + "\\" + filename, tableName =""; OleDbConnection conn = null; DataTable schemaTable, table = new DataTable(); try { conn = new OleDbConnection(databaseConn); try { conn.Open(); schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); tableName = "[" + schemaTable.Rows[0].ItemArray[2].ToString() + "];"; string sqlQuery = "SELECT * FROM " + tableName; OleDbCommand command = new OleDbCommand(sqlQuery, conn); OleDbDataReader reader; reader = command.ExecuteReader(); table.Load(reader); DataGrid_.ItemsSource = table.DefaultView; } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } finally { conn.Close(); } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } }
In the above code example, the WPF DataGrid toolkit is loaded using the MS Access database.
What I would like to do is the ability to insert a column in the DataGrid at the very beginning. This column will be used to record the line number. I think what might work is to change the table variable (which is a DataTable object ).
Question:
So, how can I insert a column into a table variable, add a row number for each row in this new column and have all the data from the database in the DataGrid?
source share