access2003数据库读取没记录只有表里的字段,代码有问题吗?
以下代码出来的结果始终是“数据为空”,可我的数据表中是有数据的。Public Class Form1
Dim data1 As New dataDataSet 'dataDataSet通过数据源添加的access2003数据库
Dim reader As DataTableReader
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
reader = data1.jbxx.CreateDataReader()
If reader.HasRows Then
While reader.Read()
TreeView1.Nodes.Add(reader.GetString(1))
reader.NextResult()
End While
Else
TreeView1.Nodes.Add("数据为空")
End If
End Sub
End Class --------------------编程问答-------------------- 貌似这是.net的代码,发错版块了吧。
ps:就算.net也要有查询语句才能知道有没有数据吧。估计你中间漏了一段吧。 --------------------编程问答-------------------- reader = data1.jbxx.CreateDataReader() 这一句不是已经针对具体的数据表创建的吗? 还需要有查询语句?
--------------------编程问答-------------------- Imports System.Data.OleDb
Public Class Form1
Dim data1 As New dataDataSet 'dataDataSet通过数据添加的access2003数据库
Dim reader As DataTableReader
Dim datarow As DataRow
Dim con As New OleDb.OleDbConnection
Dim i, j As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=D:\temp\aa\data.mdb"
Dim sqlstr As String = "select 所在科室 from jbxx group by 所在科室 having count(*)>1"
Dim oada As New OleDb.OleDbDataAdapter(sqlstr, con)
con.Open()
Dim ds As New DataSet
oada.Fill(ds)
Dim datatab As DataTableReader
datatab = ds.Tables(0).CreateDataReader
' reader = data1.jbxx.CreateDataReader()
' If reader.HasRows Then
'While reader.Read()
Dim nod(6) As TreeNode
Dim i, j As Integer
i = 0
While datatab.Read()
i = 1 + i
nod(i) = New TreeNode
nod(i) = TreeView1.Nodes.Add(datatab.GetString(0).ToString)
End While
con.Close()
sqlstr = "select 所在科室,姓名 from jbxx"
oada = New OleDbDataAdapter(sqlstr, con)
con.Open()
Dim ds1 As New DataSet
oada.Fill(ds1)
datatab = ds1.Tables(0).CreateDataReader
If datatab.HasRows Then
While datatab.Read()
datatab.GetString(0)
While i = 0
If nod(i).Text = datatab.GetString(0) Then
nod(i).Nodes.Add(datatab.GetString(1))
End If
i = i - 1
End While
End While
TreeView1.Nodes.Add("数据为空")
End If
' Else
'TreeView1.Nodes.Add("数据为空")
' End If
con.Close()
End Sub
End Class
不知什么原因,第二个查询怎么没有数据? --------------------编程问答-------------------- http://user.qzone.qq.com/631582825/blog/1320153235这个是我解决问题后的正确源代码。
补充:VB , 数据库(包含打印,安装,报表)