473,388 Members | 1,834 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,388 software developers and data experts.

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 2612
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
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.