You are Here:
FAQ
Scripting & Programming
ASP .Net
Article #2
|
ASP.Net Database Connection String<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Data
Dim oDR as System.Data.SQLClient.SQLDataReader
Dim oCom As System.Data.SQLClient.SqlCommand
Dim oConn as System.Data.SQLClient.SQLConnection
try
oConn = New System.Data.SQLClient.SQLConnection ("server=kundenmssql3.schlund.de; initial catalog=Northwind;uid=USERNAME;pwd=PASSWORD")
oConn.Open()
oCom = New System.Data.SQLClient.SqlCommand()
oCom.Connection = oConn
oCom.CommandText = "SELECT * FROM products"
oDR = oCom.ExecuteReader()
While oDR.Read
Response.Write(oDR.Item("ProductName") & ", " & oDR.Item("UnitPrice") & "£")
Response.Write("<BR/>")
End While
catch
Response.Write("Error:" & err.Description)
Finally
oDR = Nothing
oCom = Nothing
oConn.Close()
oConn = Nothing
end try
End Sub
</script>
<html>
<title>Queries from the MS-SQL database with ASP</title>
<body bgcolor="FFFFFF">
<h2>Query from table <b>products</b> with ASP.NET</h2>
<%Page_Data()%>
</body>
</html>
|
© 2007 1&1 Internet Ltd - About 1&1 Internet