网络应用与开发2

发布时间:2021-06-05

1、利用command对象的ExecuteScalar()方法读出Sample.mdb数据库中stu_info表的记录总数。

Imports System.Data

Imports ‘第一空

Private Sub insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles insert.Click

Dim objconn As New OleDbConnection ‘第二空

& Server.MapPath("sample.mdb") ‘第三空

‘第四空 Dim mySQL As String = "select count(*) from stu_info" Dim objCmd As New OleDbCommand(mySQL, objconn)

Dim totalrow As Integer = objCmd.ExecuteScalar() ‘第五空 Response.Write("记录总数为:" & totalrow) objconn.Close() End Sub

2、往sample.mdb数据库中stu_info表中插入一条记录,表中字段:学号、姓名、专业。

Imports System.Data

System.Data.OleDb ‘第一空

Private Sub insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles insert.Click

Dim objconn As New OleDbConnection ‘第二空

;Data source=" & Server.MapPath("sample.mdb") ‘第三空

objconn. ‘第四空 Dim mysql As String

mysql = "insert into stu_info(学号,姓名,专业) values('1001','王红','计算机应用')"

Dim objcmd As New OleDbCommand(mysql, objconn) ‘第五空 objconn.Close() Response.Write("一条记录插入成功") End Sub 3、用DataView对象象作为数据列表控件(DataGrid对象)的数据源,显示Sample.mdb数据库中Stu_info表的信息。

操作如下:添加Sample.mdb到项目中,插入DataGrid控件,属性均为默认,代码如

下:

Imports System.Data

Imports System.Data.OleDb

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then

Dim objconn As New OleDbConnection

objconn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Data source=" & Server.MapPath("sample.mdb") Dim mysql As String

mysql = "select * from stu_info"

Dim myda As New OleDbDataAdapter (mysql, objconn) ‘第一空 '声明一个DataSet

Dim myds As New DataSet ‘第二空 '用DataAdapter的FILL方法填充DataSet myda.Fill(myds, "学生信息表") '定义DataView对象 Dim mydv As DataView

mydv = myds.Tables("学生信息表"). DefaultView ‘第三空

DataGrid1.DataSource = mydv ‘第四空 DataGrid1. DataBind() ‘第五空 End If End Sub

4、通过DataAdapter对象获取数据库Sample.mdb中表Stu_info中的记录,并填充到DataSet对象中。 Imports System.Data

Imports System.Data.OleDb

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not Page.Then ‘第一空 Dim objconn As New OleDbConnection '设置链接字符串 objconn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;

Data source=" &Server.MapPath("sample.mdb")

‘第二空

Dim mysql As String

mysql = "select * from stu_info"

网络应用与开发2.doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219