各位帮帮忙哪位给我一个很简单的用VB.NET的SqlConnection去连接sql server数据库的b/s结构的源码程序 (50分)

  • 主题发起人 主题发起人 txdelphi
  • 开始时间 开始时间
T

txdelphi

Unregistered / Unconfirmed
GUEST, unregistred user!
程序中只要用textbox显示一个字段就可以了
我的邮箱地址是tx@exchange.ricsson.com
 
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Oledb" %>
<script language="vb" runat="server">
Sub Page_Load()
Dim strConnection as String = "Provider=Microsoft.Jet.OLEDB.4.0;"
strConnection += "Data Source=C:/BegASPNET/ch12/Northwind.mdb"
data_src.text = strConnection
Dim strSQL as string = "SELECT FirstName, LastName FROM Employees"
Dim strResultsHolder as string
Dim objConnection as New OledbConnection(strConnection)
Dim objCommand as New OledbCommand(strSQL, objConnection)
Dim objDataReader as OledbDataReader
try
objConnection.Open()
con_open.text="Connection opened successfully.<br />"
objDataReader = objCommand.ExecuteREader()
do
While objDataReader.Read()=True
strResultsHolder +=objDataREader("FirstName")
strResultsHolder +="&amp;nbsp;"
strResultsHolder +=objDataREader("LastName")
strResultsHolder +="<br>"
Loop
objDataReader.Close()
objConnection.Close()
con_close.text="Connection closed.<br>"
divListEmployees.innerHTML = strResultsHolder
catch e as Exception
con_open.text="Connection failed to open successfully.<br>"
con_close.text=e.ToString()
end try
end Sub
</script>
<html>
<body>
<h4>Reading data from the connection
<asp:label id="data_src" runat="server"/> with the DataReader object.</h4>
<asp:label id="con_open" runat="server"/><br>
<div id="divListEmployees" runat="server">list will go here</div>
<asp:label id="con_close" runat="server"/><br>
</body>
</html>
这是《begin
ning ASP.NET 1.0 with VB .NET》中的一个例子,一看就明白了。
 
后退
顶部