Sunday, February 12, 2012

ASP.net Connection String

Hi I am new to asp.net and I am having problems connecting to a SQL Server database. My code is;

Dim myConnection As New SqlConnection("server='localhost'; user id='sa'; password='ExamResults'; Database='ExamResults'")
Dim myCommand As New SqlDataAdapter("select * from tblStudents", myConnection)

Dim rstStudents As New DataSet()
myCommand.Fill(rstStudents, "tblStudents")

I'm not too sure if this should be placed in the <script runat="server"> or just after declaring the namespaces.

Also, how do you reference the select statement in the code, currently I have;

<ASP: response.write rstStudents.fields("Surname") Response.write ("test")/
Any help would be greatly appreciatedYou should look at theServer-Side Data Access quickstart for a jump start.

All of the Quickstarts can be found here: http://www.asp.net/Tutorials/quickstart.aspx

Terri

No comments:

Post a Comment