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

DataGrid Help...Please!!!

Status
Not open for further replies.

smithbr

MIS
May 29, 2003
85
US
Hello all,
I have been trying to figure out how to get a datagrid to work for way too long now and have made no progress.
I have tried to st up at design time and programatically. I think I would rather do it programatically, partially so that I can see what happens and will be able to duplicate my results if I even want to use a DataGrid again. I have scoured MSDN and tons of forums but have not found anything that will work. Does anyone have sample code that they have tested and know works that I could use to guide myself through this.
Thanks,
Brent
 
Here is the code that I haev tried to use...Maybe someone can see a problem in it that is causing me all this headache.


'Declare Variables for the Datagrid
'write the query for the datagrid
Dim strdetail As String = "SELECT InvoiceNumber, LineSEQNo, ItemNumber, ProductLine, QuantityShipped, LastUnitPrice, Total FROM InvoiceHistory WHERE InvoiceNumber = " & txtinvnum.Text & ""
'Set the data adapter and pass to it the sql statement for the datagrid (Detail) and the connection
Dim daDetail As OleDbDataAdapter = New OleDbDataAdapter(strdetail, OleDbConnection1)
'set the data set and fill it with data
Dim Detail As DataSet = New DataSet
'Set up the DataView for the datagrid
Dim DetailView As DataView = New DataView(Detail.Tables("InvoiceHistory"))

'Retreive data from the InvoiceHistory table
daDetail.Fill(Detail, "InvoiceHistory")

'Bind the data to the grid
grdcomm.DataSource = DetailView
DetailView.Sort = "ItemNumber"

The error always shows up at the "daDetail.Fill(Detail, "InvoiceHistory")" in the code.
Thanks again guys,
Brent
 

why you want use DataView???

Use DataSet, populate it using Fill method and simply bind it to the DataGrid using SetDataBinding property.

 
could you give me an example of this programatically....everything I try doesn't work
 

Dim strConn As String
Dim Conn As OleDbConnection

Dim strSQL As String
Dim objDA As OleDbDataAdapter
Dim objDS As New DataSet()

Try
'MAKE SURE TO CHANGE THE PATH OF NWIND.mdb AS PER ON YOUR MACHINE.
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.mdb"

'Create an oleDbConnection object,
'and then pass in the ConnectionString to the constructor.
Conn = New OleDbConnection(strConn)

'Initialize SQL string.
strSQL = "SELECT EmployeeID, FirstName, LastName " & _
"FROM Employees "

'Initialize the OleDbDataAdapter with strSQL and Conn.
objDA = New OleDbDataAdapter(strSQL, Conn)
'Fill the dataset with data.
objDA.Fill(objDS, "Employees")

'Bind the dataset to datagrid.
DataGrid1.SetDataBinding(objDS, "Employees")


Catch Excep As System.Exception
MessageBox.Show(Excep.Message, "Prospect Management System (searchRec)", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top