关于asp.net连接数据库的问题

来源:百度知道 编辑:UC知道 时间:2024/05/14 07:09:25
我需要一个完整的实例,谢谢大家了~~~
(请使用vb,不要用c#)

大体上是这样
有一个数据库(access)
其中有一个表table1
表如下所示(共有3条数据):
id name
id1 name1
id2 name2
id3 name3

使用asp.net读取这个数据库,并分别给变量a,b,c,d,e,f赋值id1,id2,id3,name1,name2,name3

请完整一些,并在需要的地方写上注释,谢谢

Web.config 在<configuration>下添加以下数据库连接配置

<appSettings>
<add key="strConn1" value="provider=Microsoft.Jet.OLEDB.4.0;Data Source="/>
<add key="strConn2" value="\student.mdb;"/>
</appSettings>

////////////////////建立fuction.vb 类
Imports System.Data.OleDb
Public Class fuction
Inherits System.Web.UI.Page
Public Function readchange(ByVal str As String)
Dim oleC As New OleDbConnection
oleC.ConnectionString = CType(System.Configuration.ConfigurationSettings.AppSettings("strConn1"), String) + Server.MapPath("DBC") + CType(System.Configuration.ConfigurationSettings.AppSettings("strConn2"), String)//读取Web.config 配置信息
Dim com As New OleDbCommand(str, oleC)//str为sql操作语句oleC为数据库连接字符串
Dim read As OleDbDataReader
oleC.Open()
read = com.Exe