Retrieving information from a particular record field in ASP.NET

admin

Administrator
Staff member
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?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)
 
Back
Top