Results 1 to 4 of 4

Thread: Dumb one

  1. #1

    Thread Starter
    Hyperactive Member johnweidauer's Avatar
    Join Date
    Sep 2002
    Location
    SLC, UT
    Posts
    314

    Dumb one

    Using SQL Server and ASP.Net, how do I open a recordset and set a variable to equal a field in that recordset. I only have notepad with me right now so it is proving difficult.

    Dim NewID as Integer

    Recordset = "Select MAX(ID) From myTable"

    NewID = Rs.Fields("ID")

    is the just of it.

    Thanks

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Ah, you have a lot to learn my brother. Recordsets are of the past.

    Seriously though, do some research on ADO.NET and you'll see your problem can be solved quite easily.

  3. #3
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    You'll be needing the ExecuteScalar method from the SqlCommand object.

    Code:
    int NewID;
    
    SqlCommand cmdQuery = new SqlCommand( "Select MAX(ID) From myTable", objConn );
    
    NewID = cmdQuery.ExecuteScalar();
    HTH

    DJ

  4. #4

    Thread Starter
    Hyperactive Member johnweidauer's Avatar
    Join Date
    Sep 2002
    Location
    SLC, UT
    Posts
    314

    Thanks

    Yes, I do have a lot to learn, I just jumped into this .NET stuff last week, have been focusing on asp/vb6 and finally had time to convert over.

    I had thought of using the ExecuteScalar prior to my post, but haven't read up on it so I guess education played me on this one.

    Thanks folks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width