Simple ASP.NET C# Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Validus
    Confirmed User
    • Jul 2001
    • 4012

    #1

    Simple ASP.NET C# Question

    Greetings guys, maybe somebody can help. I am working with C#.

    This is what I got:

    <%
    string MyVar; // define a variable
    MyVar = Request.QueryString["MyVar_url"]; // add value
    %>

    I am trying to grab the MyVar_url value from the URL and asign it to the MyVar varaible. I want to add it to a to this later one...


    SelectCommand="SELECT * FROM users WHERE user_id = @ MyVar "


    But that is the second step.

    Any help would be appreciated.
  • Validus
    Confirmed User
    • Jul 2001
    • 4012

    #2
    I think I am mixing run time code with compiled stuff. Umpf!

    Comment

    • woj
      <&(©¿©)&>
      • Jul 2002
      • 47882

      #3
      Is this for a school project or something?
      Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
      Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
      Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

      Comment

      • Validus
        Confirmed User
        • Jul 2001
        • 4012

        #4
        It is for me to learn a little ASP.NET C#

        Comment

        • pstation
          Confirmed User
          • Jul 2003
          • 1135

          #5
          old post, but if you're using sql server it would look something like this....

          Code:
          <%
          string MyVar = Request.QueryString["MyVar_url"];
          
          ...
          
          SqlConnection sqlConn = new SqlConnection(connectionString);
          sqlConn.Open();
          
          SqlCommand cmd = new SqlCommand("SELECT * FROM users WHERE user_id = @MyVar", sqlConn);
          cmd.Parameters.Add("@MyVar", SqlDbType.Int).Value = int.Parse(MyVar);
          SqlDataReader result = 	cmd.ExecuteReader();
          
          sqlConn.Close();
          %>
          of course, much needed exception handling is missing, but it should give you a general idea of how it could be done

          Comment

          Working...