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

Binding Datagrid to stored procedure...

Status
Not open for further replies.

sqlsamurai

Programmer
May 11, 2005
120
US
How do I bind a grid to a stored procedure in Visual Studio 2005? The twist is that I would like to setup the grid at design time. Column headings, sizes, any additional formatting that I would otherwise have to do in code. Do I somehow create a dataset to bind the grid to initially?
 
Do I somehow create a dataset to bind the grid to initially?

Yes.

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
 
You actually have to create a dataset or datatable to which to bind the grid from. You can always do a webservice and call the webmethod from your app. The service should look like this.

<WebMethod> Public Function GetDS(ByVal strConn As String) as DataSet
Dim conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim sSQL As String = ""
sSQL = "SELECT * FROM storedprocedurename"
Dim SC As New SqlClient.SqlCommand(sSQL, conn)
Dim DA As New SqlClient.SqlDataAdapter(SC)
Dim DS As New DataSet
DA.Fill(DS)
Return DS
End Function

Then you just set some dataset variable in your page or control to this webservice function and bind your grid to that datset.

You can skip the webservice step and use this same logic inside a routine in your page also.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top