datagrid not filling up

drpcken

Member
Joined
Jun 15, 2004
Messages
12
Programming Experience
1-3
[font=verdana, arial, helvetica]Usually I create my dataset, dataadapter manually in Visual Studio, but in this case, I need the dataadapter.SelectCommand to give me only rows that one column matches the value of a textbox on the webform. But it wouldn't let me do that, so I tried manualy coding the dataadapter, and dataset.

But when the page loads, there is no data in the datagrid. Am I misssing something??

Thanks again, here's the code. No errors on load, just no data in datagrid1. It shows the column headings. Pay special attention to the selectcommand of the dataadapter.


Private dsItems As New DataSet()
Private daItems As New SqlDataAdapter()


Private Sub LoadLineItems()

If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()

daItems.SelectCommand = New SqlCommand("SELECT ItemNumber, Price, Quantity from dbLineItems where RecID = '" + txtRecId.Text + "'", SqlConnection1)
daItems.Fill(dsItems)
DataGrid1.DataSource = dsItems
DataGrid1.DataBind()
SqlConnection1.Close()

End Sub
[/font]
 
Check that you've typed in the column names correctly in your select statement..

Perhaps you'd like to try putting your query in a try..catch block. this usually helps pick up any issues.

here's some code I used for one of my apps.. on form load, it fills the datagrid with all the data from a table. this isn't quite what you're after but I thought i'd throw it in just in case... im a novice at this so i apologise for any mistakes!

VB.NET:
		Try
			Me.OleDbDataAdapter1.Fill(Me.dsView)
		Catch ex As Exception
			MsgBox(ex.ToString)
		End Try
 
Last edited:
fill the dataset then use filter function to get the matched rows of the dataset

ds.tables.select(expr)

and assign this to the table row .

if no matches it return nothing . if length is more it return an array
 
Back
Top