Monday, March 26, 2012
newbie asp/ado.net question.
I am very new to .net but not new to asp or ado.
I am just wondering the best way to do the following...
I have a database which stores a list of messages/threads (like google
newsgroups threads). I want to display these on a webpage where each message
is a hyperlink, and each message has a treeview drill-down mechanism where
you can see replies for a particular message (just like in outlook express
newsgroups).
i have an aspx page which i want to display the data and an object which
should do all the retrieving/updating of data.
what is the best way to do this (in terms of using datareader, dataset,
etc). and where would be the logical place to dim these objects (asp or
object)?
one more thing... i would like to return the data from the object in XML
(unless .net has a newer easier way in presenting such information!)
thanks.One of the great things about .NET is the fact that there are tons of ways
to accomplish the same task, so I'm sure you will get tons of answers. ;-)
That being said, if all you want to do, is format the equivalent of a
forward-looking ado recordset, then I would just databind a DataReader to a
DataList or Repeater.
However, if you want to go with XML, I would bring back a dataset, and then
use the WriteXML() method.
hth,
Dave
www.aspNetEmail.com
"linz" <linz@.nospam.com> wrote in message
news:uy8yVwZQDHA.2480@.tk2msftngp13.phx.gbl...
> Hi,
> I am very new to .net but not new to asp or ado.
> I am just wondering the best way to do the following...
> I have a database which stores a list of messages/threads (like google
> newsgroups threads). I want to display these on a webpage where each
message
> is a hyperlink, and each message has a treeview drill-down mechanism where
> you can see replies for a particular message (just like in outlook express
> newsgroups).
> i have an aspx page which i want to display the data and an object which
> should do all the retrieving/updating of data.
> what is the best way to do this (in terms of using datareader, dataset,
> etc). and where would be the logical place to dim these objects (asp or
> object)?
> one more thing... i would like to return the data from the object in XML
> (unless .net has a newer easier way in presenting such information!)
> thanks.
hmm... kinda hard to answer, because I don't know enough about your app.
You wanted XML, I was just making you aware there is a WriteXML() method on
the DataSet, that's all.
If you can, I would return all the data at once, as much as makes sense.
Database connections are relatively expensive, so I would try to minimize
them to a certain extent.
I don't understand what you mean about scope, as the architecture of the web
as stayed the same (still stateless), just the way we are designing apps has
changed 1000%.
You may want to try a different ideas, and ask about more opinions.
hth,
Dave
www.aspNetEmail.com
"phillipa" <phillipa@.nospamming.com> wrote in message
news:urfF0SaQDHA.4024@.tk2msftngp13.phx.gbl...
> thanks, so do you mean dim a dataset in my object and use it to return xml
> back to the aspx page.?
> what about scope? does it work in the same way as classic asp? (ie:
> everytime a user clicks on a message, should i be recreating a connection
to
> the database in my object and populating the message data into a dataset
> then writing the xml back to the aspx page?)
> this is the bit i am unclear about.
>
> "dave wanta" <nospam@.nospam.com> wrote in message
> news:%23r09syZQDHA.2460@.TK2MSFTNGP10.phx.gbl...
> > One of the great things about .NET is the fact that there are tons of
ways
> > to accomplish the same task, so I'm sure you will get tons of answers.
;-)
> > That being said, if all you want to do, is format the equivalent of a
> > forward-looking ado recordset, then I would just databind a DataReader
to
> a
> > DataList or Repeater.
> > However, if you want to go with XML, I would bring back a dataset, and
> then
> > use the WriteXML() method.
> > hth,
> > Dave
> > www.aspNetEmail.com
> > "linz" <linz@.nospam.com> wrote in message
> > news:uy8yVwZQDHA.2480@.tk2msftngp13.phx.gbl...
> > > > Hi,
> > > > I am very new to .net but not new to asp or ado.
> > > > I am just wondering the best way to do the following...
> > > > I have a database which stores a list of messages/threads (like google
> > > newsgroups threads). I want to display these on a webpage where each
> > message
> > > is a hyperlink, and each message has a treeview drill-down mechanism
> where
> > > you can see replies for a particular message (just like in outlook
> express
> > > newsgroups).
> > > > i have an aspx page which i want to display the data and an object
which
> > > should do all the retrieving/updating of data.
> > > > what is the best way to do this (in terms of using datareader,
dataset,
> > > etc). and where would be the logical place to dim these objects (asp
or
> > > object)?
> > > > one more thing... i would like to return the data from the object in
XML
> > > (unless .net has a newer easier way in presenting such information!)
> > > > thanks.
> >
Newbie DataTable question
Just playing around with rewriting my website in .Net, I want to add a
record to my database table, in the old ADO, it was simple you could
create a connection and recordset and then rs.AddNew etc... in .Net it
seems they recommend that you populate a DataTable then use the
NewRow method
Isnt this bringing back a entire copy of the table (in this case 40,000
users), if so isn't this very inefficient? I know you can run a
insert via a ExecuteNonQuery which is the way I have done it in the
past (usually passing parameters to stored procs)
But I would have thought you should be able to add a row (Datarow) in
this case to a table without returning the entire table when you
connect to it.
Probably being very stupid
heres my code
try
{
// Initializations
string database = "MyDB.mdb";
string connectionString =
@dotnet.itags.org."Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Z:\Web\Database\" +
database;
//connection
OleDbConnection cnn = new OleDbConnection();
cnn.ConnectionString = connectionString;
cnn.Open();
OleDbCommand com = cnn.CreateCommand();
com.CommandText = "Select * from tblUser";
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = com;
//DataSet ds = new DataSet();
//da.Fill(ds, "Users");
DataTable dt = new DataTable();
da.Fill(dt);
//DataRow dr = dt.Rows[0];
DataRow dr = dt.NewRow();
dr["FirstName"] = FirstName.ToString();
dr["Surname"] = Surname.ToString();
dr["Email"] = Email.ToString();
dt.Rows.Add(dr);
da.Update(dt);
//close up
cnn.Close();
}
catch (OleDbException ee)
{
Console.WriteLine(ee.ToString());
}the notion of in-memory datasets, is you only keep a copy of what you need.
the premise is that normally you only need a subset of the data. a dataset
keeps track of the status of a row (new, modified,deleted,unchanged). then
the adapter can look at the row status to determine whether to insert,
delete, update, or do nothing.
in your case you are loading the dataset solely to get the structure. you
could use the folowwing statement.
com.CommandText = "Select * from tblUser where 1 = 0";
which would only return column info and no data. a better approach is to use
typed datasets. here you use a wizard to build a dataset class that initials
the table and column info. this removes the requirement to do a dummy
database select. also you get a dot notion for accessing column data.
-- bruce (sqlwork.com)
"Ben" <BenScott@.aemail4u.com> wrote in message
news:1151423636.132121.107680@.75g2000cwc.googlegro ups.com...
> Stupid question for the day,
>
> Just playing around with rewriting my website in .Net, I want to add a
> record to my database table, in the old ADO, it was simple you could
> create a connection and recordset and then rs.AddNew etc... in .Net it
> seems they recommend that you populate a DataTable then use the
> NewRow method
>
> Isnt this bringing back a entire copy of the table (in this case 40,000
> users), if so isn't this very inefficient? I know you can run a
> insert via a ExecuteNonQuery which is the way I have done it in the
> past (usually passing parameters to stored procs)
>
> But I would have thought you should be able to add a row (Datarow) in
> this case to a table without returning the entire table when you
> connect to it.
>
> Probably being very stupid
> heres my code
> try
> {
> // Initializations
> string database = "MyDB.mdb";
> string connectionString =
> @."Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Z:\Web\Database\" +
> database;
> //connection
> OleDbConnection cnn = new OleDbConnection();
> cnn.ConnectionString = connectionString;
> cnn.Open();
> OleDbCommand com = cnn.CreateCommand();
> com.CommandText = "Select * from tblUser";
> OleDbDataAdapter da = new OleDbDataAdapter();
> da.SelectCommand = com;
> //DataSet ds = new DataSet();
> //da.Fill(ds, "Users");
> DataTable dt = new DataTable();
> da.Fill(dt);
> //DataRow dr = dt.Rows[0];
> DataRow dr = dt.NewRow();
> dr["FirstName"] = FirstName.ToString();
> dr["Surname"] = Surname.ToString();
> dr["Email"] = Email.ToString();
> dt.Rows.Add(dr);
> da.Update(dt);
> //close up
> cnn.Close();
> }
> catch (OleDbException ee)
> {
> Console.WriteLine(ee.ToString());
> }
thanks Bruce,
yeah as you where writing i had tried that, bit quicker, but then it
wont allow me to insert data
"Update requires a valid InsertCommand when passed DataRow collection
with new rows."
so i guess i need to change
da.SelectCommand = com;
to
da.InsertCommand = com;
that doesnt work :(. any more words of wisdom? the main reason i am
doing this is to avoid having to handle what data is being put into
each field when the users submit the data. creating a Insert string
seem to me the wrong way to do this.
Newbie DataTable question
Just playing around with rewriting my website in .Net, I want to add a
record to my database table, in the old ADO, it was simple you could
create a connection and recordset and then rs.AddNew etc... in .Net it
seems they recommend that you populate a DataTable then use the
NewRow method
Isnt this bringing back a entire copy of the table (in this case 40,000
users), if so isn't this very inefficient? I know you can run a
insert via a ExecuteNonQuery which is the way I have done it in the
past (usually passing parameters to stored procs)
But I would have thought you should be able to add a row (Datarow) in
this case to a table without returning the entire table when you
connect to it.
Probably being very stupid
heres my code
try
{
// Initializations
string database = "MyDB.mdb";
string connectionString =
@dotnet.itags.org."Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Z:\Web\Database\" +
database;
//connection
OleDbConnection cnn = new OleDbConnection();
cnn.ConnectionString = connectionString;
cnn.Open();
OleDbCommand com = cnn.CreateCommand();
com.CommandText = "Select * from tblUser";
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = com;
//DataSet ds = new DataSet();
//da.Fill(ds, "Users");
DataTable dt = new DataTable();
da.Fill(dt);
//DataRow dr = dt.Rows[0];
DataRow dr = dt.NewRow();
dr["FirstName"] = FirstName.ToString();
dr["Surname"] = Surname.ToString();
dr["Email"] = Email.ToString();
dt.Rows.Add(dr);
da.Update(dt);
//close up
cnn.Close();
}
catch (OleDbException ee)
{
Console.WriteLine(ee.ToString());
}the notion of in-memory datasets, is you only keep a copy of what you need.
the premise is that normally you only need a subset of the data. a dataset
keeps track of the status of a row (new, modified,deleted,unchanged). then
the adapter can look at the row status to determine whether to insert,
delete, update, or do nothing.
in your case you are loading the dataset solely to get the structure. you
could use the folowwing statement.
com.CommandText = "Select * from tblUser where 1 = 0";
which would only return column info and no data. a better approach is to use
typed datasets. here you use a wizard to build a dataset class that initials
the table and column info. this removes the requirement to do a dummy
database select. also you get a dot notion for accessing column data.
-- bruce (sqlwork.com)
"Ben" <BenScott@.aemail4u.com> wrote in message
news:1151423636.132121.107680@.75g2000cwc.googlegroups.com...
> Stupid question for the day,
>
> Just playing around with rewriting my website in .Net, I want to add a
> record to my database table, in the old ADO, it was simple you could
> create a connection and recordset and then rs.AddNew etc... in .Net it
> seems they recommend that you populate a DataTable then use the
> NewRow method
>
> Isnt this bringing back a entire copy of the table (in this case 40,000
> users), if so isn't this very inefficient? I know you can run a
> insert via a ExecuteNonQuery which is the way I have done it in the
> past (usually passing parameters to stored procs)
>
> But I would have thought you should be able to add a row (Datarow) in
> this case to a table without returning the entire table when you
> connect to it.
>
> Probably being very stupid
> heres my code
> try
> {
> // Initializations
> string database = "MyDB.mdb";
> string connectionString =
> @."Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Z:\Web\Database\" +
> database;
> //connection
> OleDbConnection cnn = new OleDbConnection();
> cnn.ConnectionString = connectionString;
> cnn.Open();
> OleDbCommand com = cnn.CreateCommand();
> com.CommandText = "Select * from tblUser";
> OleDbDataAdapter da = new OleDbDataAdapter();
> da.SelectCommand = com;
> //DataSet ds = new DataSet();
> //da.Fill(ds, "Users");
> DataTable dt = new DataTable();
> da.Fill(dt);
> //DataRow dr = dt.Rows[0];
> DataRow dr = dt.NewRow();
> dr["FirstName"] = FirstName.ToString();
> dr["Surname"] = Surname.ToString();
> dr["Email"] = Email.ToString();
> dt.Rows.Add(dr);
> da.Update(dt);
> //close up
> cnn.Close();
> }
> catch (OleDbException ee)
> {
> Console.WriteLine(ee.ToString());
> }
>
thanks Bruce,
yeah as you where writing i had tried that, bit quicker, but then it
wont allow me to insert data
"Update requires a valid InsertCommand when passed DataRow collection
with new rows."
so i guess i need to change
da.SelectCommand = com;
to
da.InsertCommand = com;
that doesnt work :(. any more words of wisdom? the main reason i am
doing this is to avoid having to handle what data is being put into
each field when the users submit the data. creating a Insert string
seem to me the wrong way to do this.
Saturday, March 24, 2012
Newbie Forms Question
Hello All -
I have intermediate experience with MS SQL 2000 Server Programming and now getting into .net, ASP.net, VB.net and ADO.net to be more specific.
I was given this simple project to build a data entry form to insert some data in a SQL table. I have the form ready and need some help on how to take the data from my form (text box, drop downs) and send to my sql table, I've read some articles about data adapter but still not sure how to use that.
I'm also consfused between using the code on the web page or the code behind.
Any light you guys can shed will be welcome, thanks in advance.
Depends on what version of ASP.NET you're working with. If using 2.0, then I suggest you read through the following. Lots of info there with examples...http://www.asp.net/QuickStart/aspnet/Default.aspx
Thursday, March 22, 2012
newbie issue - asp.net file displays as source
I just setup the .NET framework for asp.net. I have programmed regular
csharp and ado.net programs before. I use the Borland CSharpBuilder IDE
I am having a problem that must have a simple solution.- any aspx file I
create within the IDE and then Run, opens as source in Internet Explorer.
The same file, say one of the quickstart examples run from the quickstart
page opens as expected in rendered html.
What am I doing wrong?
TIA
aacoolThere's a readme file that comes with the Resource Kit. Here's a snippet on installing ASP.NET
2) Install ASP.NET - > From a command prompt window, run the following command from your windows directory: \Microsoft.NET\Framework\version\aspnet_regiis -i
Where version is the version number of the .NET Framework is installed on your machine (v1.1.4322, for example).
Note with Windows Server 2003, you can install ASP.NET using the Add or Remove Programs Control Panel.
Hope this helps...
"=?Utf-8?B?UmljaGllQQ==?=" <anonymous@.discussions.microsoft.com> wrote
in news:79616F35-16F1-4E07-AA4C-41BE37FD10E7@.microsoft.com:
> There's a readme file that comes with the Resource Kit. Here's a
> snippet on installing ASP.NET:
> 2) Install ASP.NET - > From a command prompt window, run the following
> command from your windows directory:
> \Microsoft.NET\Framework\version\aspnet_regiis -i Where version is the
> version number of the .NET Framework is installed on your machine
> (v1.1.4322, for example).
> Note with Windows Server 2003, you can install ASP.NET using the Add
> or Remove Programs Control Panel.
> Hope this helps...
Thanks for your response - it sounded right - I followed it, and the
additional step mentioned in msdn of registering the aspnet_isapi dll -
regsvr32 %windir%\Microsoft.NET\Framework\v1.1.4322\aspnet_ isapi.dll
This has not helped - I still see only the source code and am unable to see
the rendered html correctly.
Please advise
aacool
you need to type this at the command prompt
\Microsoft.NET\Framework\version\aspnet_regiis -i
^^^^^^^^
and then hit Enter. I've installed it on a couple of machines this way. Give it a try if you haven't as yet
Good luck..
2) Install ASP.NET - > From a command prompt window, run the followin
> command from your windows directory
> \Microsoft.NET\Framework\version\aspnet_regiis -i Where version is th
> version number of the .NET Framework is installed on your machin
> (v1.1.4322, for example).
"=?Utf-8?B?UmljaGllQQ==?=" <anonymous@.discussions.microsoft.com> wrote
in news:968CBAD1-E3FC-45F6-AFD6-B47FE4A97AD9@.microsoft.com:
> you need to type this at the command prompt :
> \Microsoft.NET\Framework\version\aspnet_regiis -i
> ^^^^^^^^^
> and then hit Enter. I've installed it on a couple of machines this
> way. Give it a try if you haven't as yet.
> Good luck...
> 2) Install ASP.NET - > From a command prompt window, run the
> following
>> command from your windows directory:
>> \Microsoft.NET\Framework\version\aspnet_regiis -i Where version is
>> the version number of the .NET Framework is installed on your machine
>> (v1.1.4322, for example).
TY - I did exactly that, but the problem remains
aacool