Hi Everyone.
Can you show me what the most effecient way to load data from a data adapter in textboxes would be?
I heard that binding data to the textboxes is a better way but this is how I have been doing it so far:
' Compose the SELECT statement to first display the data to update.
'------------------------------------------------------------------
SqlStatement =
"Select Shape " & _
"From Shapes " & _
"Where ID = @ID "
headerDetails.Text = "Edit Shape"
Try
' Create the connection object.
'------------------------------
objConnection = New SqlConnection(FormMain.strDatabaseConnection)
' Start out clean.
'-----------------
objDataSetShapeDetails.Clear()
' Create an instance of the data adapter and then fill with data.
'----------------------------------------------------------------
objDataAdapterShapeDetails = _
New SqlDataAdapter(SqlStatement, objConnection)
' Assign the primary key value into data adapter parameter.
'----------------------------------------------------------
objDataAdapterShapeDetails.SelectCommand.Parameters. _
AddWithValue("@ID", strStringFromSearch)
' Fill the dataset with data.
'----------------------------
Dim intTotalRowsFound As Integer = 0
intTotalRowsFound = objDataAdapterShapeDetails.Fill(objDataSetShapeDetails, _
"Shape Details")
' Load data into the edit boxes.
'-------------------------------
editBoxShapeName.Text = _
objDataSetShapeDetails.Tables("Shape Details").Rows(0) _
.Item("Shape").ToString
Catch exSqlErrors As SqlException
MessageBox.Show("Sorry, I had trouble with your data " & _
"because of this SQL error:" & vbCrLf & vbCrLf & exSqlErrors.Message, _
"Other Error")
Catch exErrors As Exception
MessageBox.Show("Sorry, I had trouble with your data " & _
"because of this error:" & vbCrLf & vbCrLf & exErrors.Message, _
"Other Error")
Finally
objConnection.Close()
End Try
If data binding is the best way, can you change the code so it can use data binding?
Thanks.
Truly,
Emad