这段代码究竟做了什么? [英] What does this code do exactly?

查看:56
本文介绍了这段代码究竟做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

受保护的子Button1_Click(发件人为对象,e为EventArgs)处理Button1.Click





Dim conn As New OleDbConnection( Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\ Users \Draus \Documents\Visual Studio 2012 \WebSites\sampledb\Database5.accdb;)





Dim cmd当OleDbCommand =新OleDbCommand(SELECT F_Name FROM [Bowlers],conn)







conn.Open()

Dim读取为OleDbDataReader = cmd.ExecuteReader()

如果read.HasRows然后

当read.Read()

Dim Fname As String = read.Item(F_Name)

结束时

结束如果



结束Sub

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Draus\Documents\Visual Studio 2012\WebSites\sampledb\Database5.accdb;")


Dim cmd As OleDbCommand = New OleDbCommand("SELECT F_Name FROM [Bowlers]", conn)



conn.Open()
Dim read As OleDbDataReader = cmd.ExecuteReader()
If read.HasRows Then
While read.Read()
Dim Fname As String = read.Item("F_Name")
End While
End If

End Sub

推荐答案

它连接到ms访问数据库,从Bowlers表中检索F_name列数据,然后遍历i t使用读取器将数据存储在名为FName的变量中。奇怪的是,它似乎没有对var做任何事情,也没有返回它。除非我遗漏了什么,否则它不会做任何永久性的事情。即使它对FName变量做了某些事情,它也只有数据集中最后一行的值。
It connects to a ms access database, retrieves the F_name column data from the Bowlers table and then iterates through it with a reader storing the data in a variable named FName. Strangely, it doesn't seem to do anything with the var, nor return it. Unless I am missing something it isn't doing anything permanent. Even if it did something with the FName variable, it would only have the value of the last row in the dataset.


这篇关于这段代码究竟做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆