Megalith
Well-known member
- Joined
- Aug 21, 2006
- Messages
- 66
- Programming Experience
- 10+
Hi can anyone help me with this. I have been following techgnome's excellent article Introduction to ADO.NET, Part 2 (http://www.developerkb.com/modules/wfsection/article.php?articleid=58) the article is great and has explained a lot to me about databases in VB.NET the problem i have is in the final part of the article having created the CurrentCellChanged event and copied the code into it i get an error saying it wont convert to a string. Heres the code from the Article
this the code in my test application where i have altered the code with no remedy.
the exact error message i recieve in the error list is
Value of type 'System.Windows.Forms.DataGridViewCell' cannot be converted to 'String'.
can anyone tell me how this should be done in VB?
VB.NET:
[COLOR=#000080][B] Dim[/B][/COLOR] CustID [COLOR=#000080][B]As[/B][/COLOR] [COLOR=#000080][B]String[/B][/COLOR]
CustID = Customers.Item(Customers.CurrentRowIndex, 0)
[COLOR=#000080][B]Dim[/B][/COLOR] DBConnection [COLOR=#000080][B]As[/B][/COLOR] New SqlClient.SqlConnection(MyCONNECTIONSTRING)
[COLOR=#000080][B]Dim[/B][/COLOR] SelectHistory [COLOR=#000080][B]As[/B][/COLOR] New SqlClient.SqlCommand("CustOrderHist", DBConnection)
SelectHistory.CommandType = CommandType.StoredProcedure
[COLOR=#000080][B]Dim[/B][/COLOR] SelectHistoryParameter [COLOR=#000080][B]As[/B][/COLOR] SqlClient.SqlParameter = SelectHistory.CreateParameter
SelectHistoryParameter.ParameterName = "@CustomerID"
SelectHistoryParameter.Value = CustID
SelectHistory.Parameters.Add(SelectHistoryParameter)
[COLOR=#000080][B]Dim[/B][/COLOR] HistoryAdaptor [COLOR=#000080][B]As[/B][/COLOR] New SqlClient.SqlDataAdapter(SelectHistory)
[COLOR=#000080][B]Dim[/B][/COLOR] ds [COLOR=#000080][B]As[/B][/COLOR] New System.Data.DataSet
Try
HistoryAdaptor.Fill(ds, "CustomerHistory")
Catch sqlex [COLOR=#000080][B]As[/B][/COLOR] SqlClient.SqlException
MessageBox.Show(sqlex.ToString)
Catch ex [COLOR=#000080][B]As[/B][/COLOR] Exception
MessageBox.Show(ex.ToString)
[COLOR=#000080][B]End[/B][/COLOR] Try
CustomerHistory.DataSource = ds
CustomerHistory.DataMember = "CustomerHistory
VB.NET:
Private Sub Customers_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Customers.CurrentCellChanged
Dim CustID As String
[B][I]CustID = Customers.Item(0, Customers.CurrentRow.Index)[/I][/B]
Dim DBConnection As New SqlClient.SqlConnection(MyCONNECTIONSTRING)
Dim SelectHistory As New SqlClient.SqlCommand("CustOrderHist", DBConnection)
SelectHistory.CommandType = CommandType.StoredProcedure
Dim SelectHistoryParameter As SqlClient.SqlParameter = SelectHistory.CreateParameter
SelectHistoryParameter.ParameterName = "@CustomerID"
SelectHistoryParameter.Value = CustID
SelectHistory.Parameters.Add(SelectHistoryParameter)
Dim HistoryAdaptor As New SqlClient.SqlDataAdapter(SelectHistory)
Dim ds As New System.Data.DataSet
Try
HistoryAdaptor.Fill(ds, "CustomerHistory")
Catch sqlex As SqlClient.SqlException
MessageBox.Show(sqlex.ToString)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
CustomerHistory.DataSource = ds
CustomerHistory.DataMember = "CustomerHistory"
End Sub
Value of type 'System.Windows.Forms.DataGridViewCell' cannot be converted to 'String'.
can anyone tell me how this should be done in VB?