Urgent Help PLEASE w/databind + SQL + vb.net

handleWithBeer
02-05-2004, 11:04 AM
Greetings.

I posted in another area, but am doing so here due to the urgency of my situation. Just a question about getting information from an SQL dBase, and putting it in a listbox. Right now, the formatting is not important. I just need the info.

So, here's the code, BTW the SQL statement does work, as I tried it in Query Analyser. And I have broken the functions in diff. modules for reusability. I think the problem is that I have several fields in the query. Also, unlike ASP.net, there seems to be no option called DataBind(), which is used after Object.DataSource().

The Code.
'//////////////////Make the connection
Public Function getDataset(ByVal SQL As String) As DataSet

Dim con As New SqlConnection(stuff here)
Dim adapter As New SqlDataAdapter(SQL, con)
Dim myData As New DataSet

adapter.Fill(myData)
adapter.Dispose()
con.Close()

Return myData

End Function

'///////////////the Query
Public Function getProjectInfoDS(ByVal projectName As String) As DataSet
Try
Dim strSQL As String

strSQL = "select a.name,a.id,a.defaultUserID,b.ID,b.fName,b.lName,c.Title,c.ID,c.Report edDate,c.AssignedToID "
strSQL += "FROM tblProject a inner join tblUser b ON a.defaultUserID=b.ID inner join tblBug c "
strSQL += "ON a.defaultUserID=c.AssignedToID WHERE a.Name LIKE '" & projectName & "'"

Return mdlDa.getDataset(strSQL.ToString)

Catch ex As DataException
MsgBox(ex.ToString)
End Try

End Function

'//////////////////in the form itself
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick

Dim x As SqlDataReader = mdlDQ.getProjectInfoDR(ListBox1.SelectedItem)

While x.Read
ListBox2.Items.Add(x("Name") & vbNewLine)

End While


End Sub

If I do a x.HasRows, I get false. The same if I try and use a dataSet.

Any help is appreciated. I think that I am missing a few small bits, as usual.

Cheers

VBJoe
02-05-2004, 10:08 PM
What is the error that query analyzer throws (if any)? That might help pinpoint the problem. Also, when you run the query in QA, are you using the exact string stored in strSQL? If not, set a breakpoint to get the value to paste into QA.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum