[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

DataGridView data binding (ADO.NET 2.0)

Posted on 2006-06-12
5
Medium Priority
?
2,420 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,
0
Comment
Question by:SEANWYATT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
vadim63 earned 1500 total points
ID: 16889283
A good example:

' Assumes that connection is a valid SqlConnection object.
Dim adapter As SqlDataAdapter = New SqlDataAdapter( _
  "SELECT CategoryID, CategoryName FROM dbo.Categories", connection)

adapter.InsertCommand = New SqlCommand("InsertCategory", connection)
adapter.InsertCommand.CommandType = CommandType.StoredProcedure

adapter.InsertCommand.Parameters.Add( _
  "@CategoryName", SqlDbType.NChar, 15, "CategoryName")

Dim parameter As SqlParameter = adapter.InsertCommand.Parameters.Add( _
  "@Identity", SqlDbType.Int, 0, "CategoryID")
parameter.Direction = ParameterDirection.Output

connection.Open()

Dim categories As DataSet = New DataSet
adapter.Fill(categories, "Categories")

Dim newRow As DataRow = categories.Tables("Categories").NewRow()
newRow("CategoryName") = "New Category"
categories.Tables("Categories").Rows.Add(newRow)

adapter.Update(categories, "Categories")

connection.Close()
0
 

Author Comment

by:SEANWYATT
ID: 16889352
OK but how does this data get into the datagridview control?
0
 
LVL 10

Expert Comment

by:vadim63
ID: 16889428
DataGridView1.DataSource = categories.Tables("Categories")
0
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 16889441
the datasource for your datagridview needs to be a datatable/dataview not a datareader.

stealing from vadim's example:

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

Author Comment

by:SEANWYATT
ID: 16889531
OK Thanks. I was trying to do it without the table defiined but now it makes sense.

I appreciate the quick response.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question