Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updateable DataGrid

Status
Not open for further replies.

toon10

Programmer
Mar 26, 2004
303
DE
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
 
OK thanks

I'll take a look.

Andrew
 
aarrghh, apparently it can't be done. It only works on single tables.
 
Yes, Same rules applies as database update. For instance, if you have a view that pulls data from multiple tables you can not use that to update data! But you can execute more than one update commands to achieve that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top