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

Filling DataGrid

Status
Not open for further replies.

GerardMcL

Technical User
Aug 5, 2004
212
IE
Hi,

cmd = New OleDbCommand("SELECT s.Title + '. ' + s.FirstName + ' ' + s.LastName AS Staff, th.Location1, th.Location2, th.Date FROM ToolHire th INNER JOIN Staff s ON th.StaffID = s.StaffID WHERE th.ToolID = '" & ToolCode & "';", cn)
dr = cmd.ExecuteReader
DGrid1.DataSource = dr

This is what I tried but it doesnt work. Is there a way this can be done?
Or would I have to do something like DGrid1.col(0) = dr(0)?

Thank You.
 
Try using a DataAdapter and DataTable instead of a Command and DataReader:

Dim da As OleDbDataAdapter
Dim dt As DataTable
dim SQLStr As String

SQLStr = "SELECT s.Title + '. ' + s.FirstName + ' ' + s.LastName AS Staff, th.Location1, th.Location2, th.Date FROM ToolHire th INNER JOIN Staff s ON th.StaffID = s.StaffID WHERE th.ToolID = '" & ToolCode & "';"

da = New OleDbDataAdapter(SQLStr, cn)
dt = New DataTable
da.Fill(dt)

DGrid1.DataSource = dt

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top