473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Fill GridView

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

Oct 26 '06 #1
1 5796
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

--
David Longnecker
Web Developer
http://blog.tiredstudent.com
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

Oct 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chuck Gantz | last post by:
I've manually created a database (based on the Manage a Music Collection ... article on theMSDN site) with three data tables. I then populated the tables with data. When I preview the data, I...
0
by: T. Wong | last post by:
I always liked doing my own MyDataAdapter.fill(myDataSet1). I had control. Just like when you drive a stick shift. Now the new DataSource (or is it a TableAdatper:Dataset) automatically fills...
0
by: RWF | last post by:
I have been trying to dynamically fill a gridview based on a userID (basically the userID is a serialized class that represents type int: Myuser.UserID) My web.config defines a connection string...
3
by: Advertis | last post by:
Is there a way to populate a dropdown in a GridView with the next x years? I am using a GridView to display data from a SQL table One of the fields is a Year. I want to have the dropdown list not...
0
by: mike1402 | last post by:
Hi ! I get the error below sometimes when retrieving a big amount of data using Datadapter.Fill(dataset,"table"). But when I send the command Fill again, there is no error. Is it a fault of...
3
by: phanimadhav | last post by:
hi this is sudheer, i am new one of this ASP.NET .i have one problem,i am using gridview control i know how to place the dropdownlistbox in gridview control.in my gridveiw control have contain...
1
by: Ajumal | last post by:
i want to fill my gridview from textbox.no database should be used. The process must done in a button click
3
by: ASPnewb1 | last post by:
I am currently filling a dataTable then adding this table to a dataset, setting the dataset to the Gridview's datasource. If I set the Gridview to generate columns automatically it will fill the...
1
by: mik | last post by:
Hi, How Can I fill a DDL in a grid view? <asp:TemplateField HeaderText="AAA" SortExpression="AAA"> <ItemTemplate> <div align="left"> <asp:DropDownList ID="ddlPorssima" runat="server"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.