A
Andrew Dodgshun
I have 2 grids - one shows a list of table names in a database and
when you click on a table name the other grid dynamically populates
the grid with the table contents. My problem is that I cannot get any
changes I do in the grid of a given table saved back to the database
unless I nominate a particular table in the SQLDataAdapter but this is
not dynamic as the table changes when the user picks another table
I have the first part working nicely this way..
' for the list of table names
dim cmd = New System.Data.SqlClient.SqlCommand("SELECT name FROM
sysobjects WHERE (xtype = 'U') and name <> 'dtproperties'",
SqlConnection)
SqlDataAdapterVOL.SelectCommand = cmd
DataSetVOL.Clear()
SqlDataAdapterVOL.Fill(DataSetVOL)
DataGridVol.Expand(-1)
DataGridVol.DataMember = DataSetVOL.Tables(0).TableName
DataGridVol.Select(0)
'for the table contents
cmd = "SELECT * FROM " &
DataGridVol.Item(DataGridVol.CurrentCell.RowNumber, 0), SqlConnection)
SqlDataAdapterVOL.SelectCommand = cmd
DataSetWI.Tables.Clear()
DataSetWI.Tables.Add(DataGridVol.Item(DataGridVol.CurrentCell.RowNumber,
0))
SqlDataAdapterVOL.Fill(DataSetWI, DataGridVol.Item
DataGridVol.CurrentCell.RowNumber, 0))
DataGridWI.DataSource = DataSetWI
DataGridWI.Expand(-1)
DataGridWI.DataMember = DataSetWI.Tables(0).TableName
but when I want to update a cell in a table it
does not update in the database unless the table is specified in the
adapter with all the sql command for update, delete etc.
Do I have to programmatically update the SQL "update" command for the
new table ? Or is there a way for it to work out the update command
dynamically given I know the newly selected table name ?
'the update bit I use is
DataSetWI.Tables(0).Rows(row).Item(i) = Avalue
DataGridWI.Item(row, i) = Avalue
Dim cb As New System.Data.SqlClient.SqlCommandBuilder(SqlDataAdapterWI)
SqlDataAdapterWI.Update(DataSetWI, DataGridVol.Item
DataGridVol.CurrentCell.RowNumber, 0))
Maybe its not possible to use a SQLDataAdapter on more than one table
?
thanks
Andrew
when you click on a table name the other grid dynamically populates
the grid with the table contents. My problem is that I cannot get any
changes I do in the grid of a given table saved back to the database
unless I nominate a particular table in the SQLDataAdapter but this is
not dynamic as the table changes when the user picks another table
I have the first part working nicely this way..
' for the list of table names
dim cmd = New System.Data.SqlClient.SqlCommand("SELECT name FROM
sysobjects WHERE (xtype = 'U') and name <> 'dtproperties'",
SqlConnection)
SqlDataAdapterVOL.SelectCommand = cmd
DataSetVOL.Clear()
SqlDataAdapterVOL.Fill(DataSetVOL)
DataGridVol.Expand(-1)
DataGridVol.DataMember = DataSetVOL.Tables(0).TableName
DataGridVol.Select(0)
'for the table contents
cmd = "SELECT * FROM " &
DataGridVol.Item(DataGridVol.CurrentCell.RowNumber, 0), SqlConnection)
SqlDataAdapterVOL.SelectCommand = cmd
DataSetWI.Tables.Clear()
DataSetWI.Tables.Add(DataGridVol.Item(DataGridVol.CurrentCell.RowNumber,
0))
SqlDataAdapterVOL.Fill(DataSetWI, DataGridVol.Item
DataGridVol.CurrentCell.RowNumber, 0))
DataGridWI.DataSource = DataSetWI
DataGridWI.Expand(-1)
DataGridWI.DataMember = DataSetWI.Tables(0).TableName
but when I want to update a cell in a table it
does not update in the database unless the table is specified in the
adapter with all the sql command for update, delete etc.
Do I have to programmatically update the SQL "update" command for the
new table ? Or is there a way for it to work out the update command
dynamically given I know the newly selected table name ?
'the update bit I use is
DataSetWI.Tables(0).Rows(row).Item(i) = Avalue
DataGridWI.Item(row, i) = Avalue
Dim cb As New System.Data.SqlClient.SqlCommandBuilder(SqlDataAdapterWI)
SqlDataAdapterWI.Update(DataSetWI, DataGridVol.Item
DataGridVol.CurrentCell.RowNumber, 0))
Maybe its not possible to use a SQLDataAdapter on more than one table
?
thanks
Andrew