Is This Really that Difficult?

Discussion in 'ASP .Net' started by Paul Smith, Dec 8, 2005.

  1. Paul Smith

    Paul Smith Guest

    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.
    Paul Smith, Dec 8, 2005
    #1
    1. Advertising

  2. Paul Smith

    KJ Guest

    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
    KJ, Dec 8, 2005
    #2
    1. Advertising

  3. Paul Smith

    john_teague Guest

    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.
    john_teague, Dec 8, 2005
    #3
  4. Paul Smith

    Paul Smith Guest

    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" <> wrote in message
    news:...
    > 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.
    >
    Paul Smith, Dec 8, 2005
    #4
  5. Paul Smith

    Paul Smith Guest

    Any chance of a VB.NET example?


    "KJ" <> wrote in message
    news:...
    > 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
    >
    Paul Smith, Dec 8, 2005
    #5
  6. 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" <> wrote in message
    news:4397897c$0$82675$...
    >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.
    >
    >
    >
    Kevin Spencer, Dec 8, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amir
    Replies:
    3
    Views:
    594
  2. nc
    Replies:
    1
    Views:
    493
    nice.guy.nige
    Feb 3, 2005
  3. Mike Dee
    Replies:
    12
    Views:
    928
    Paul Boddie
    Feb 23, 2005
  4. Replies:
    2
    Views:
    335
  5. ICPooreMan
    Replies:
    4
    Views:
    120
    Wenzel.Peppmeyer
    Apr 7, 2007
Loading...

Share This Page