quote:Originally posted by akibaMaila
I comment out the sqldataadapter.SelectCommand.ExecuteNonQuer y()
code and code the MessageBox.Show as suggested but it still does not work. The MessageBox.Show does show that my sql is as it should be.
I should mention that my form is populated with data on a form level. In addition, it has a textbox1 and a button1 so that I can filter the data and only show the data i am interested in.
Any suggestions would be greatly appreciated.
Here's some example code that I use to do essentially the same type of thing. It sounds to me like your connection string might be the problem - it doesn't seem like the connection is being established:
here is some working code that I use...
' set up the datasets etc
Dim objConnection As SqlConnection = New _
SqlConnection("server=wfntmetersidb1; database=NUEVEE_MAIN; user id=userid; password=password")
Dim objDataAdapter As New SqlDataAdapter
' Dim objDataSet As DataSet = New DataSet
' Set the SelectCommand Properties.....
objDataAdapter.SelectCommand = New SqlCommand
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter.SelectCommand.CommandText = _
"SELECT dbo.GroupHdr.name AS Groupnme, " & _
"dbo.Recorder.recid as Recorder, " & _
"dbo.Account.name AS Name " & _
"FROM dbo.GroupHdr INNER JOIN " & _
"dbo.GroupElement ON dbo.GroupHdr.gid = dbo.GroupElement.gid " & _
"INNER JOIN dbo.Recorder ON dbo.GroupElement.elementid = dbo.Recorder.rid " & _
"INNER JOIN dbo.Account ON dbo.Recorder.aid = dbo.Account.aid " & _
"WHERE dbo.GroupHdr.Name = '" & cboGroup.SelectedValue & "' " & _
"ORDER BY dbo.GroupHdr.name, dbo.Recorder.recid"
objDataAdapter.SelectCommand.CommandType = CommandType.Text
' Open the database Connection
objDataSet = Nothing
objDataSet = New DataSet
' fill the dataset with data
The line of code below can be uncommented to show you the number of rows returned: