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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to fill a datagrid via sql string...

Status
Not open for further replies.

sk8er1

Programmer
Jan 2, 2005
229
US

I am passing in a sql string into the function. When it
hits the da.Fill ... I get object reference not set to instance of an object....


Private Sub FillDataGrid(ByVal strSQL)
'-- the filldata grid sub will create a dataset that
'-- will be used to populate a grid
Dim strConn As String = "server=EdsLapTop;database=Voters;" _
& "integrated security=SSPI"

Dim conVoters As New SqlConnection()
conVoters.ConnectionString = strConn
conVoters.Open()
Try
sql = "SELECT * FROM VOTERS "
sql = sql & "WHERE " & strSQL
conVoters = New SqlConnection(strConn)
ds = New DataSet("Voters")
da.Fill(ds, "Voters")

grdVoters.DataSource = ds.Tables(0).DefaultView

Catch ex As Exception
MsgBox("Error: " & ex.Source & " : " & _
ex.Message, MsgBoxStyle.OKOnly, "btnSelect")
End Try

conVoters.Close()
conVoters.Dispose()


End Sub


Thanks for any help on this one...really stumped
 
I got it...it was a stupid error. I used the wrong table name. Duh!!!!!!!!!!!
 
Also, you seem to build a select statement string that is not used, you just open the whole table instead ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top