Hi
I have a DataGrid called DGResults, which goes off and displays data from different tables (like a view.) What I want to do is be able to update some of the columns of the DataGrid (i.e. there’s a flag field I want to be able to select and have the table with the flag in it updated.) I’m not sure how easy this is to achieve. Any ideas?
Here’s my code to display the data, which works, but the DataGrid is not updateable.
Public Sub DisplayData()
Dim MyConnString As String
MyConnString = "Initial Catalog=Data;Data Source=SQLSVR;Integrated Security=SSPI;"
Dim SqlDisplay As String
SqlDisplay = "SELECT, blah blah "
Dim MyDataAdapterDisplay As New System.Data.SqlClient.SqlDataAdapter
MyDataAdapterDisplay = Nothing
Dim MyDataSet As DataSet
MyDataSet = Nothing
Try
Dim MyConnection As SqlConnection
MyConnection = New SqlConnection(MyConnString)
MyDataAdapterDisplay = New
System.Data.SqlClient.SqlDataAdapter(SqlDisplay, MyConnection)
MyDataSet = New DataSet
MyDataAdapterDisplay.ContinueUpdateOnError = True
MyDataAdapterDisplay.Fill(MyDataSet, "results")
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Insert Error –
Display Data")
Return
End Try
'datagrid display
Dim tableStyle As DataGridTableStyle
tableStyle = New DataGridTableStyle
tableStyle.MappingName = "results"
DGResults.TableStyles.Clear()
DGResults.TableStyles.Add(tableStyle)
DGResults.DataSource = MyDataSet.Tables("results") DGResults.CaptionText = ("Results. "
& MyDataSet.Tables(0).Rows.Count & " Records.")
AutoSizeTable() 'auto size routine for the grid columns
End Sub
Thanks
Andrew
I have a DataGrid called DGResults, which goes off and displays data from different tables (like a view.) What I want to do is be able to update some of the columns of the DataGrid (i.e. there’s a flag field I want to be able to select and have the table with the flag in it updated.) I’m not sure how easy this is to achieve. Any ideas?
Here’s my code to display the data, which works, but the DataGrid is not updateable.
Public Sub DisplayData()
Dim MyConnString As String
MyConnString = "Initial Catalog=Data;Data Source=SQLSVR;Integrated Security=SSPI;"
Dim SqlDisplay As String
SqlDisplay = "SELECT, blah blah "
Dim MyDataAdapterDisplay As New System.Data.SqlClient.SqlDataAdapter
MyDataAdapterDisplay = Nothing
Dim MyDataSet As DataSet
MyDataSet = Nothing
Try
Dim MyConnection As SqlConnection
MyConnection = New SqlConnection(MyConnString)
MyDataAdapterDisplay = New
System.Data.SqlClient.SqlDataAdapter(SqlDisplay, MyConnection)
MyDataSet = New DataSet
MyDataAdapterDisplay.ContinueUpdateOnError = True
MyDataAdapterDisplay.Fill(MyDataSet, "results")
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Insert Error –
Display Data")
Return
End Try
'datagrid display
Dim tableStyle As DataGridTableStyle
tableStyle = New DataGridTableStyle
tableStyle.MappingName = "results"
DGResults.TableStyles.Clear()
DGResults.TableStyles.Add(tableStyle)
DGResults.DataSource = MyDataSet.Tables("results") DGResults.CaptionText = ("Results. "
& MyDataSet.Tables(0).Rows.Count & " Records.")
AutoSizeTable() 'auto size routine for the grid columns
End Sub
Thanks
Andrew