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

create a datagrid without the tree view (+)

Status
Not open for further replies.

jennyflower

Programmer
Oct 10, 2006
60
GB
Hi, Im am just really learning vb.net using visual studio 2003 and I am trying to get some data from SQL Server Express 2005 into my datagrid.

I currently have this:

Public Sub GridMyDataOle(ByVal myConnString As String)
Dim mySelectQuery As String = "SELECT TOP 10 h_order_no FROM order_header"
Dim myConnection As New OleDbConnection(myConnString)
Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
myConnection.Open()
Dim myAdapter As New OleDbDataAdapter(myCommand)
Dim myDataSet As New DataSet
myAdapter.Fill(myDataSet, "order_header")
Me.DataGrid1.SetDataBinding(myDataSet, "")
myConnection.Close()
End Sub 'Ole DB - GridMyDataOle

I get the data in the grid doing this but I want to do it without the user having to select the (+) key or any navigation.

None of the books I have read mention this part!

Thanks
 
It's been a while since I used a DataGrid so I'm throwing out a guess here - but I believe it is because it is a DataSet you are using.

Try either using a DataTable (to fill and set the binding to) or set the binding to the myDataSet.Tables(0) - or the first DataTable in the tables array of the DataSet.
 
Thanks, That was just what I needed. It gave me a shove in the right direction so I found a website which had a code snippet which gave me another shove to some code alterations and although slightly bruised it now works how I wanted it to!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top