Click to See Complete Forum and Search --> : Retrieving information from a particular record field in ASP.NET


beta
07-29-2005, 09:45 AM
I am finding this much more difficult to do in .NET than in classic ASP.

The example is: I wish to execute an SQL string "SELECT Name From Members Where ID = 1", then I wish to view "name" to the page. In ASP I would use the recordset function and display "name" like rs("Name"). How would this be done is ASP.NET?

Cstick
07-29-2005, 10:30 PM
Dim strName As String
Dim myConn As New System.Data.SqlClient.SqlConnection("Your connection string")
Dim myCmd As New System.Data.SqlClient.SqlCommand("SELECT Name FROM Members Where ID = 1",myConn)
myConn.Open()
strName = myCmd.ExecuteScalar()
myConn.Close()

Response.Write(strName)