We help IT Professionals succeed at work.

DataGridView data binding (ADO.NET 2.0)

SEANWYATT
SEANWYATT asked
on
2,453 Views
Last Modified: 2008-02-01
I would like to use the results of a stored procedure to fill a datagridview. I am not using the Data Set IDE and created the Stored Procedure objects manually. I added a blank datagridview control to the form named dgPartInfo but don't know where to go from here:

        Dim cmdGetPartInfo As New SqlCommand("SW_GET_PART_BASICS", dbConn) ' gets header info from part table
        cmdGetPartInfo.CommandType = CommandType.StoredProcedure
        cmdGetPartInfo.Parameters.AddWithValue("@PART_ID", strPartID)
        Dim PartReader As SqlDataReader = cmdGetPartInfo.ExecuteReader
        dgPartInfo.DataSource = PartReader

I am moving from mostly VB6 experience to .NET 2.0 so am not very familiar with the datagrid and datagrid view controls or the difference between them. All the documantation I can find only shows how to poulate a grid by dragging items from the Data Set IDE.

Thanks,
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
OK but how does this data get into the datagridview control?

Commented:
DataGridView1.DataSource = categories.Tables("Categories")
Brian CroweDatabase Engineer
CERTIFIED EXPERT
Top Expert 2005

Commented:
the datasource for your datagridview needs to be a datatable/dataview not a datareader.

stealing from vadim's example:

dgpartinfo.datasource = categories.tables("categories")

Author

Commented:
OK Thanks. I was trying to do it without the table defiined but now it makes sense.

I appreciate the quick response.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.