473,473 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

simple data example

Hi. I am trying to get used to AS.NET. I have been doing ASP classic for
years, and am now in a position to do ASP.NET. I am in the stumbling
around until I get my bearings phase. I hope you will bear with me. I am
going through the QuickStart. After reading a little, I am trying to
implement a simple page on a simple project I have made up. I have a page
called default.aspx. I want it to load a list of user names from a SQL
database when the page loads.

Observe this from the HTML view
<asp:datalist id=dlUsers runat="server" BorderColor="#C00000" BorderStyle="Double"></asp:DataList>

(I added the border because I could not tell if the datalist was absent or
the data which should be IN the datalist.

Observe the underlying class code:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
String connectionString = "Initial
Catalog=Grocery;Data Source=localhost;user=Grocery";
DataSet ds = new DataSet();
SqlConnection cn = new SqlConnection(connectionString);
cn.Open();
//SqlCommand cmd = new SqlCommand("Select * From UserQualifiedName", cn);
//cmd.CommandType = CommandType.Text;

String select = "SELECT UserID, LastName + ', ' +
FirstName AS Name FROM dbo.[User]";
SqlDataAdapter da = new SqlDataAdapter(select, cn);

da.Fill(ds);
dlUsers.DataSource = ds;
dlUsers.DataBind();
}

This code runs, but it does not list in the datalist. The datalist
displays as I see a tiny red box completely empty of content. I am not
seeing any methods for the SqlDataAdapter like Open or Make It So Number
1. There is defintely a record in the table in question.

Can anyone give me a nudge on what I might be doing wrong? My handy dandy
ASP.NET books won't arrive from amazon until tomorrow.

Thanks!

S

Nov 18 '05 #1
5 2619
On Mon, 23 Aug 2004 08:48:09 -0700, <St*************@IDX.COM> wrote:
Hi. I am trying to get used to AS.NET. I have been doing ASP classic for
years, and am now in a position to do ASP.NET. I am in the stumbling
around until I get my bearings phase. I hope you will bear with me. I am
going through the QuickStart. After reading a little, I am trying to
implement a simple page on a simple project I have made up. I have a page
called default.aspx. I want it to load a list of user names from a SQL
database when the page loads.

Observe this from the HTML view
<asp:datalist id=dlUsers runat="server" BorderColor="#C00000"
BorderStyle="Double"></asp:DataList>

(I added the border because I could not tell if the datalist was absent
or
the data which should be IN the datalist.

Observe the underlying class code:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
String connectionString = "Initial
Catalog=Grocery;Data Source=localhost;user=Grocery";
DataSet ds = new DataSet();
SqlConnection cn = new
SqlConnection(connectionString);
cn.Open();
//SqlCommand cmd = new SqlCommand("Select * From
UserQualifiedName", cn);
//cmd.CommandType = CommandType.Text;

String select = "SELECT UserID, LastName + ', ' +
FirstName AS Name FROM dbo.[User]";
SqlDataAdapter da = new SqlDataAdapter(select,
cn);

da.Fill(ds);
dlUsers.DataSource = ds;
dlUsers.DataBind();

}

This code runs, but it does not list in the datalist. The datalist
displays as I see a tiny red box completely empty of content. I am not
seeing any methods for the SqlDataAdapter like Open or Make It So Number
1. There is defintely a record in the table in question.

Can anyone give me a nudge on what I might be doing wrong? My handy dandy
ASP.NET books won't arrive from amazon until tomorrow.

Thanks!

S

You need to define an ItemTemplate for the DataList (inside of it); right
now you haven't defined anything for the content of each item. Only the
DataGrid can auto-generate its columns.....

The QuickStart should show how to do this...or Google a little on DataList
and ItemTemplate...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #2
Why is the command code commented out? think you were closer with that

SqlCommand cmd = new SqlCommand("Select..", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd)
DataSet ds = new DataSet();
da.Fill(da)

cmd.dispose()
cn.dispose()..

off the top of my head that is..

Karl

<St*************@IDX.COM> wrote in message
news:OH*************@TK2MSFTNGP10.phx.gbl...
Hi. I am trying to get used to AS.NET. I have been doing ASP classic for
years, and am now in a position to do ASP.NET. I am in the stumbling
around until I get my bearings phase. I hope you will bear with me. I am
going through the QuickStart. After reading a little, I am trying to
implement a simple page on a simple project I have made up. I have a page
called default.aspx. I want it to load a list of user names from a SQL
database when the page loads.

Observe this from the HTML view
<asp:datalist id=dlUsers runat="server" BorderColor="#C00000" BorderStyle="Double"></asp:DataList>
(I added the border because I could not tell if the datalist was absent or
the data which should be IN the datalist.

Observe the underlying class code:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
String connectionString = "Initial
Catalog=Grocery;Data Source=localhost;user=Grocery";
DataSet ds = new DataSet();
SqlConnection cn = new SqlConnection(connectionString); cn.Open();
//SqlCommand cmd = new SqlCommand("Select * From UserQualifiedName", cn); //cmd.CommandType = CommandType.Text;

String select = "SELECT UserID, LastName + ', ' +
FirstName AS Name FROM dbo.[User]";
SqlDataAdapter da = new SqlDataAdapter(select, cn);
da.Fill(ds);
dlUsers.DataSource = ds;
dlUsers.DataBind();
}

This code runs, but it does not list in the datalist. The datalist
displays as I see a tiny red box completely empty of content. I am not
seeing any methods for the SqlDataAdapter like Open or Make It So Number
1. There is defintely a record in the table in question.

Can anyone give me a nudge on what I might be doing wrong? My handy dandy
ASP.NET books won't arrive from amazon until tomorrow.

Thanks!

S

Nov 18 '05 #3
Ooppss..:) I thought she was using a dropdownlist :) You can use a
datagrid instead of a list to get things to automatically show up.

Karl

"Craig Deelsnyder" <cdeelsny@no_spam_4_meyahoo.com> wrote in message
news:op**************@web-1161d.webservices.nrt...
On Mon, 23 Aug 2004 08:48:09 -0700, <St*************@IDX.COM> wrote:
Hi. I am trying to get used to AS.NET. I have been doing ASP classic for
years, and am now in a position to do ASP.NET. I am in the stumbling
around until I get my bearings phase. I hope you will bear with me. I am going through the QuickStart. After reading a little, I am trying to
implement a simple page on a simple project I have made up. I have a page called default.aspx. I want it to load a list of user names from a SQL
database when the page loads.

Observe this from the HTML view
<asp:datalist id=dlUsers runat="server" BorderColor="#C00000"
BorderStyle="Double"></asp:DataList>

(I added the border because I could not tell if the datalist was absent
or
the data which should be IN the datalist.

Observe the underlying class code:

private void Page_Load(object sender, System.EventArgs e) {
// Put user code to initialize the page here
String connectionString = "Initial
Catalog=Grocery;Data Source=localhost;user=Grocery";
DataSet ds = new DataSet();
SqlConnection cn = new
SqlConnection(connectionString);
cn.Open();
//SqlCommand cmd = new SqlCommand("Select * From
UserQualifiedName", cn);
//cmd.CommandType = CommandType.Text;

String select = "SELECT UserID, LastName + ', ' + FirstName AS Name FROM dbo.[User]";
SqlDataAdapter da = new SqlDataAdapter(select,
cn);

da.Fill(ds);
dlUsers.DataSource = ds;
dlUsers.DataBind();

}

This code runs, but it does not list in the datalist. The datalist
displays as I see a tiny red box completely empty of content. I am not
seeing any methods for the SqlDataAdapter like Open or Make It So Number
1. There is defintely a record in the table in question.

Can anyone give me a nudge on what I might be doing wrong? My handy dandy ASP.NET books won't arrive from amazon until tomorrow.

Thanks!

S

You need to define an ItemTemplate for the DataList (inside of it); right
now you haven't defined anything for the content of each item. Only the
DataGrid can auto-generate its columns.....

The QuickStart should show how to do this...or Google a little on DataList
and ItemTemplate...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #4
I am now officially confused about things I used to understand in ASP! All
I want to do is have a list similar to <SELECT of yonder days. I want the
items in a SQL Server View to show in the list. In the olden days of my
youth, this would have been done by looping through a recordset with a
forward only/read only cursor. The options seem to be:

1. A DataList bound to a DataSet which is populated by a DataAdapter. This
is what I seem to have tried to do here. (I have tried a bunch of things
and am QUITE confused.) I apparently am missing only ItemTemplate in this
case. (The QuickStart did not seem to cover the ItemTemplate at all,
unless my brain is squishy.)

2. Somehow I ought to be able to use a DataReader. But I cannot see what
control is best used with DataReader and how. It seems that if you use
these server side controls, instead of HTML tags, the controls maintain
some kind of state through the use of corresponding hidden elements so
that trips to the server still yield the same value in the control. This
is pretty nifty. So what control plays nice with DataReader?

I am screwed when I have to do something HARD! Just kidding. It is always
like this for me. Early in the learning phase I resemble a fish flapping
on the beach. After a while I will start getting familiar!

Thanks for your help.

S

Ooppss..:) I thought she was using a dropdownlist :) You can use a
datagrid instead of a list to get things to automatically show up.

Karl

"Craig Deelsnyder" <cdeelsny@no_spam_4_meyahoo.com> wrote in message
news:op**************@web-1161d.webservices.nrt...
On Mon, 23 Aug 2004 08:48:09 -0700, <St*************@IDX.COM> wrote:
Hi. I am trying to get used to AS.NET. I have been doing ASP classic for years, and am now in a position to do ASP.NET. I am in the stumbling around until I get my bearings phase. I hope you will bear with me. I
am
going through the QuickStart. After reading a little, I am trying to
implement a simple page on a simple project I have made up. I have a page called default.aspx. I want it to load a list of user names from a
SQL database when the page loads.

Observe this from the HTML view
<asp:datalist id=dlUsers runat="server" BorderColor="#C00000"
BorderStyle="Double"></asp:DataList>

(I added the border because I could not tell if the datalist was absent or
the data which should be IN the datalist.

Observe the underlying class code:

private void Page_Load(object sender, System.EventArgs
e) {
// Put user code to initialize the page here
String connectionString = "Initial
Catalog=Grocery;Data Source=localhost;user=Grocery";
DataSet ds = new DataSet();
SqlConnection cn = new
SqlConnection(connectionString);
cn.Open();
//SqlCommand cmd = new SqlCommand("Select * From UserQualifiedName", cn);
//cmd.CommandType = CommandType.Text;

String select = "SELECT UserID, LastName +
', '
+ FirstName AS Name FROM dbo.[User]";
SqlDataAdapter da = new
SqlDataAdapter(select, cn);

da.Fill(ds);
dlUsers.DataSource = ds;
dlUsers.DataBind();

}

This code runs, but it does not list in the datalist. The datalist
displays as I see a tiny red box completely empty of content. I am not seeing any methods for the SqlDataAdapter like Open or Make It So > Number 1. There is defintely a record in the table in question.

Can anyone give me a nudge on what I might be doing wrong? My handy dandy ASP.NET books won't arrive from amazon until tomorrow.

Thanks!

S

You need to define an ItemTemplate for the DataList (inside of it);

right now you haven't defined anything for the content of each item. Only the DataGrid can auto-generate its columns.....

The QuickStart should show how to do this...or Google a little on > DataList and ItemTemplate...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Nov 18 '05 #5
I'm afraid I might have added unnecessary confusion to your situation. But
if you do want a <select you want to use a DropDownList, not a datalist.

<asp:dropdownlist id="ddl" runat="server" />
// Put user code to initialize the page here
String connectionString = "Initial Catalog=Grocery;Data
Source=localhost;user=Grocery";
DataSet ds = new DataSet();
SqlConnection cn = new SqlConnection(connectionString);
cn.Open();
//SqlCommand cmd = new SqlCommand("Select * From UserQualifiedName", cn);
//cmd.CommandType = CommandType.Text;

String select = "SELECT UserID, LastName + ', ' + FirstName AS Name FROM
dbo.[User]";
SqlDataAdapter da = new SqlDataAdapter(select, cn);

da.Fill(ds);
ddl.DataSource = ds;
ddl.DataTextField = "Name" 'this is new
ddl.DataValueField = "UserId 'this is new
ddl.DataBind();
Don't worry about datalist's for now :)

As for the datareader vs the dataset it doesn't have anything to do with the
control you are using it with, but how you want to deal with the actual data
container (datareader or dataset). The datareader is connected to the
database and can only be read forward - once. it's like a forward-only
recordset in ASP. It can't be cached, you can't loop through it twice or do
fancy things with it, but man it's fast ;) The Dataset is diconnected. The
minute you do a Da.fill(ds), the dataset is a full blown asp.net object -
forget the database. It can be cached in memory, you can add rows to it (it
won't add them automatically to the database though), you can add columns,
loop through it as many times as you want...it's a lot more like an array
from that sense...

Hope this helps.

karl
<St*************@IDX.COM> wrote in message
news:eh*************@tk2msftngp13.phx.gbl...
I am now officially confused about things I used to understand in ASP! All
I want to do is have a list similar to <SELECT of yonder days. I want the
items in a SQL Server View to show in the list. In the olden days of my
youth, this would have been done by looping through a recordset with a
forward only/read only cursor. The options seem to be:

1. A DataList bound to a DataSet which is populated by a DataAdapter. This
is what I seem to have tried to do here. (I have tried a bunch of things
and am QUITE confused.) I apparently am missing only ItemTemplate in this
case. (The QuickStart did not seem to cover the ItemTemplate at all,
unless my brain is squishy.)

2. Somehow I ought to be able to use a DataReader. But I cannot see what
control is best used with DataReader and how. It seems that if you use
these server side controls, instead of HTML tags, the controls maintain
some kind of state through the use of corresponding hidden elements so
that trips to the server still yield the same value in the control. This
is pretty nifty. So what control plays nice with DataReader?

I am screwed when I have to do something HARD! Just kidding. It is always
like this for me. Early in the learning phase I resemble a fish flapping
on the beach. After a while I will start getting familiar!

Thanks for your help.

S

Ooppss..:) I thought she was using a dropdownlist :) You can use a
datagrid instead of a list to get things to automatically show up.

Karl

"Craig Deelsnyder" <cdeelsny@no_spam_4_meyahoo.com> wrote in message
news:op**************@web-1161d.webservices.nrt...
On Mon, 23 Aug 2004 08:48:09 -0700, <St*************@IDX.COM> wrote:

> Hi. I am trying to get used to AS.NET. I have been doing ASP classic

for
> years, and am now in a position to do ASP.NET. I am in the stumbling > around until I get my bearings phase. I hope you will bear with me. I
am
> going through the QuickStart. After reading a little, I am trying to
> implement a simple page on a simple project I have made up. I have a

page
> called default.aspx. I want it to load a list of user names from a

SQL > database when the page loads.
>
> Observe this from the HTML view
>
>
> <asp:datalist id=dlUsers runat="server" BorderColor="#C00000"
> BorderStyle="Double"></asp:DataList>
>
> (I added the border because I could not tell if the datalist was absent > or
> the data which should be IN the datalist.
>
> Observe the underlying class code:
>
> private void Page_Load(object sender, System.EventArgs
e)
> {
> // Put user code to initialize the page here
> String connectionString = "Initial
> Catalog=Grocery;Data Source=localhost;user=Grocery";
> DataSet ds = new DataSet();
> SqlConnection cn = new
> SqlConnection(connectionString);
> cn.Open();
> //SqlCommand cmd = new SqlCommand("Select *

From
> UserQualifiedName", cn);
> //cmd.CommandType = CommandType.Text;
>
> String select = "SELECT UserID, LastName +

', '
+
> FirstName AS Name FROM dbo.[User]";
> SqlDataAdapter da = new

SqlDataAdapter(select, > cn);
>
> da.Fill(ds);
> dlUsers.DataSource = ds;
> dlUsers.DataBind();
>
> }
>
> This code runs, but it does not list in the datalist. The datalist
> displays as I see a tiny red box completely empty of content. I am not > seeing any methods for the SqlDataAdapter like Open or Make It So > Number > 1. There is defintely a record in the table in question.
>
> Can anyone give me a nudge on what I might be doing wrong? My handy

dandy
> ASP.NET books won't arrive from amazon until tomorrow.
>
> Thanks!
>
> S
>
You need to define an ItemTemplate for the DataList (inside of it); right now you haven't defined anything for the content of each item. Only the DataGrid can auto-generate its columns.....

The QuickStart should show how to do this...or Google a little on > DataList and ItemTemplate...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Nov 18 '05 #6

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

Similar topics

4
by: Paul Moore | last post by:
I hit a problem yesterday with my mail connection. In a desparate attempt to understand what was going on, I wanted to log the connection traffic. After a bit of searching, I found a post on c.l.p...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
3
by: suzy | last post by:
Hello, I am trying to write a generic tool that accesses a SQL server and reads/updates/deletes/creates records. I want to reference this tool from my asp.net pages to talk to my db. by the...
9
by: Pete | last post by:
Does anyone have a simple html vbscript or other type of snippet they can share that appends a record to a access database via ADO or DAO? I would like to allow users that don't have Microsoft...
0
by: Tal Sharfi | last post by:
Hi everyone I recently had the need for StringGrid object same as the one that Delphi has. An object that helps show lists of other objects in a simple grid. I searched the news groups and...
10
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when...
1
by: Brian Henry | last post by:
Hello, I was tring to learn socket's (being i never used them before) and have a simple question. I want to create a listner that will get any data recieved and print it out. I've been able to...
0
by: minnie | last post by:
An AJAX Simple Example for PHP Article from http://www.joyistar.com Introduction: AJAX WebShop 3 Beta2 supports PHP programming by integrating PHP5 development environment. Here we will give an...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.