Fill GridView

S

shapper

Hello,

I am working on an Asp.Net 2.0 web site.
In have a GridView which I want to fill using a DataSource Function.
What data type should I use to how to get the data from the database?

Here is my DataSource function with "??????" on the 2 places where I am
having problems.

Function DataSource() As ??????

' Define connection
Dim connection As New
SqlClient.SqlConnection("MyConnectionString")

' Define command
Dim command As New SqlClient.SqlCommand
With command
.CommandText = "MyCommand"
.Connection = connection
.CommandType = CommandType.StoredProcedure
End With

' Execute the command
connection.Open()
???????????????
connection.Close()

End Function

Thanks,
Miguel
 
D

David R. Longnecker

The part you're missing is dropping it into a Dataset, table, or row (depending
on your expect returns) from the SqlDataAdapter.

--

Include System.Data
Include System.Data.SqlClient

Dim connection as New SqlConnection("MyConnectionString")
Dim command as New SqlCommand
Dim adapter as New SqlDataAdapter(command)

With command
.Command.Text = "MyCommand"
.Connection = connection
.CommandType = CommandType.StoredProcedure
End With

Dim ds as New DataSet()
adapter.fill(ds)

connection.Close()

GridView1.DataSource = ds
GridView1.DataBind()

--

Apologize in advance if some of the exact syntax is a bit off--trying to
convert from C# to VB (fun times).

-dl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top