Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Is This Really that Difficult?

Reply
Thread Tools

Is This Really that Difficult?

 
 
Paul Smith
Guest
Posts: n/a
 
      12-08-2005
I am sorry but this is killing me.....

On one page I have a DropDownList from which the user makes a selection.
This is then passed to another page as a Request variable.

On the load of the new page I want to use this Request variable to query a
Access DB and return all the fields the row specified by the Request
Variable (which is a primary key).

I think want to put each field into a named label e.g. lblTest1 = 'Field1',
lblTest2 'Field2' etc.

I know the syntax will be something like.... lblTest1.text = ???????

I think I would like ???? to be some DataView reference.

This was so easy on ASP using a Recordset, to me it is so complecated in
ASP.NET, so I am thinking I must be misunderstanding something.



 
Reply With Quote
 
 
 
 
KJ
Guest
Posts: n/a
 
      12-08-2005
Hey Paul,

Basically, in ASP.NET, when returning data, you are dealing primarily
with the DataSet object, and the DataTable object. DataViews can be
added to the mix to manipulate (e.g., sort) the data in a DataTable, if
need be.

Take a look at th MSDN topic "Using .NET Framework Data Providers to
Access Data" for starters, it contains a wealth of information.

If you want a shortcut, you can use something like the method below
(C#), which takes a stored procedure name, a connection string, and a
hashtable of parameters, and returns a DataTable from the stored proc.

You can then use this proc in your aspx page such as:

//quasi-pseudocode

Hastable h = new Hashtable();
h.Add("@inputparam1", somevariable);
DataTable dt = GenericSP("procname", "connection string", h);
lblWhatever.Text = dt.Rows[rowindex]["columnname"].ToString();

//real method here
public DataTable GenericSP(string SpName, string ConnectionString,
Hashtable Parameters)
{
using (SqlConnection c = new SqlConnection(ConnectionString))
{
using (SqlCommand o = new SqlCommand(SpName, c))
{
using (SqlDataAdapter a = new SqlDataAdapter(o))
{
try
{

o.CommandType = CommandType.StoredProcedure;

if (Parameters != null && Parameters.Keys.Count > 0)
{
IDictionaryEnumerator ie = Parameters.GetEnumerator();
while (ie.MoveNext())
{
o.Parameters.Add(ie.Key.ToString(), ie.Value);
}
}

c.Open();
DataTable d = new DataTable(SpName);
a.Fill(d);
return d;
}
catch
{
throw;
}
}
}
}
}

--KJ

 
Reply With Quote
 
 
 
 
john_teague
Guest
Posts: n/a
 
      12-08-2005
The standard asp.net way to do this is to use only one web page.
either autopostback the dropdown list and use the SelectedIndexChanged
event or use a button and bth Click event to get the SelectedValue from
the drop down list and populated your dataset / dataview.

changing to the one page model with different events is sometimes
difficult to get used to from classic asp, where the only event was the
form submission.

 
Reply With Quote
 
Paul Smith
Guest
Posts: n/a
 
      12-08-2005
Thanks John, but I have already mastered the change of page.

My problem is displaying individual fields from a referenced table records
in label fields. I hope when I fully understand KJ's post that will help
me.

Many thanks to both of you for trying to help me.


"john_teague" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> The standard asp.net way to do this is to use only one web page.
> either autopostback the dropdown list and use the SelectedIndexChanged
> event or use a button and bth Click event to get the SelectedValue from
> the drop down list and populated your dataset / dataview.
>
> changing to the one page model with different events is sometimes
> difficult to get used to from classic asp, where the only event was the
> form submission.
>



 
Reply With Quote
 
Paul Smith
Guest
Posts: n/a
 
      12-08-2005
Any chance of a VB.NET example?


"KJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hey Paul,
>
> Basically, in ASP.NET, when returning data, you are dealing primarily
> with the DataSet object, and the DataTable object. DataViews can be
> added to the mix to manipulate (e.g., sort) the data in a DataTable, if
> need be.
>
> Take a look at th MSDN topic "Using .NET Framework Data Providers to
> Access Data" for starters, it contains a wealth of information.
>
> If you want a shortcut, you can use something like the method below
> (C#), which takes a stored procedure name, a connection string, and a
> hashtable of parameters, and returns a DataTable from the stored proc.
>
> You can then use this proc in your aspx page such as:
>
> //quasi-pseudocode
>
> Hastable h = new Hashtable();
> h.Add("@inputparam1", somevariable);
> DataTable dt = GenericSP("procname", "connection string", h);
> lblWhatever.Text = dt.Rows[rowindex]["columnname"].ToString();
>
> //real method here
> public DataTable GenericSP(string SpName, string ConnectionString,
> Hashtable Parameters)
> {
> using (SqlConnection c = new SqlConnection(ConnectionString))
> {
> using (SqlCommand o = new SqlCommand(SpName, c))
> {
> using (SqlDataAdapter a = new SqlDataAdapter(o))
> {
> try
> {
>
> o.CommandType = CommandType.StoredProcedure;
>
> if (Parameters != null && Parameters.Keys.Count > 0)
> {
> IDictionaryEnumerator ie = Parameters.GetEnumerator();
> while (ie.MoveNext())
> {
> o.Parameters.Add(ie.Key.ToString(), ie.Value);
> }
> }
>
> c.Open();
> DataTable d = new DataTable(SpName);
> a.Fill(d);
> return d;
> }
> catch
> {
> throw;
> }
> }
> }
> }
> }
>
> --KJ
>



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      12-08-2005
Hi Paul,

One of the main differences between ASP and ASP.Net is that ASP.Net has a
structured methodology, and a set of pre-built classes that are designed to
work in a certain way, whereas ASP simply has a language and syntax. The
advantage of ASP.Net over ASP is that with the pre-existing structure of
ASP.Net, once you learn how it operates, you have a broad set of tools that
work in a uniform way, and can develop applications quickly that adhere to a
set of pre-defined rules. With ASP, you make up your own methodology (or
not), and hand-code the entire thing from scratch with every project. This
makes ASP.Net easier to maintain and extend, as all ASP.Net apps adhere to a
basic set of rules, and easier to use in a team, for the same reason.

The difficulty in ASP.Net arises in learning the programming and object
model, which is ingenious but complex. It entails more work and study up
front with a serious increase in productivity and ease of development over
the long term.

Underneath it all, you could ostensibly "roll your own" ASP.Net, and it
would operate in much the same way as ASP. Underneath it all, you are still
writing text to a Response stream. But that would not be productive in the
long run.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Paul Smith" <(E-Mail Removed)> wrote in message
news:4397897c$0$82675$(E-Mail Removed)...
>I am sorry but this is killing me.....
>
> On one page I have a DropDownList from which the user makes a selection.
> This is then passed to another page as a Request variable.
>
> On the load of the new page I want to use this Request variable to query a
> Access DB and return all the fields the row specified by the Request
> Variable (which is a primary key).
>
> I think want to put each field into a named label e.g. lblTest1 =
> 'Field1', lblTest2 'Field2' etc.
>
> I know the syntax will be something like.... lblTest1.text = ???????
>
> I think I would like ???? to be some DataView reference.
>
> This was so easy on ASP using a Recordset, to me it is so complecated in
> ASP.NET, so I am thinking I must be misunderstanding something.
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
really interesting... or really dull. (depends on your attitude) TrevorBoydSmith@gmail.com Java 2 09-01-2006 04:38 PM
OT : But help really really needed re: Domain Name selling, hosting etc. problem nc HTML 1 02-03-2005 07:24 PM
REALLY REALLY WERID PROBLEM!!!!pls take a look Amir ASP .Net 3 01-23-2004 06:01 PM
really really mysterious IE6 problem--secure site ultraviolet353 Computer Support 7 11-22-2003 07:56 PM
MR. ED REALLY, REALLY LOVES THE D60 !!! Annika1980 Digital Photography 9 10-28-2003 04:53 PM



Advertisments