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