Is This Really that Difficult?

P

Paul Smith

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.
 
K

KJ

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
 
J

john_teague

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.
 
P

Paul Smith

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.
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top