Pete Lux

I'm pretty new at VB .net (using express 2005) but not new to programming. I'm trying to get quotes from our production system into a data grid. I don't get any errors, but I don't get the grid to show. Do you have to create columns before it'll appear I tried to do this programmatically since I'm going to have to do things like dynamic sql/parameters/stored procs in the future.

(gvQuote is a DataGridView)

Private Sub pbFill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbFill.Click

Dim hConnect As New SqlConnection(cnctStr)

Dim sSelect As String = "select quote_nbr from quote where" & _

" co_nbr=8 and locn_id=99 and expire_date is null order by cust_id"

Dim sqlCmd As New SqlCommand(sSelect, hConnect)

Dim da As New SqlDataAdapter

Dim ds As New DataSet

Dim bs As New BindingSource

Try

hConnect.Open()

If hConnect.State = ConnectionState.Open Then

'MsgBox("we are open for business")

da.SelectCommand = sqlCmd

da.Fill(ds)

gvQuote.DataSource = ds

End If

hConnect.Close()

Catch ex As Exception

End Try

End Sub



Re: Visual Basic Express Edition DataGridView won't show

js06

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






Re: Visual Basic Express Edition DataGridView won't show

Pete Lux

I know this is stupid, but why do you have to specify "Tables(0)" There's several rows to the result set, but just one set.





Re: Visual Basic Express Edition DataGridView won't show

js06

To my knowledge when you create a new dataset and fill it it creates a new table for you. Many items start with 0 instead of 1. Like in a table - the first row is actually row 0. Since you have created the first table it is table 0. Even if you use a named table if it is the first table in your database then technically it is table 0. Except we refer to it by name.

I still have not found the reason to create a new dataset with code like this. A dataset has more functionality to it like realations. I have just been creating a new table and then fill the table. I don't know how much of a difference it really makes one way or another. I just like to eliminate the clutter. I don't rely on the relationships anyway, i am creating my own code to handle the parent and child records. Basically your exisitng database is a dataset.