access 不能返回其值
2005订单信息表 有8个字段
问题就是:我的订单信息表不是全部字段都有数据的,有些字段是空的,留给其它的功能。这样用下面的方法查询成功,但TextBox数据都没返回Commonmodule.myrow.Item的值
如果订单信息表中的数据全都不为空 就没问题了,但我有些字段必需留空,留给其它的功能,再建一个表也太麻烦了。请问如何解决?代码该怎样改?
数据库是access的
Module.vb 类代码
Imports System.Data.OleDb
Module Commonmodule
'定义适配器
Public mydap As OleDbDataAdapter
'建立DataSet对象
Public mydataset As DataSet = New DataSet
'定义一个表对象
Public mytable As DataTable
'定义一个行对象
Public myrow As DataRow
'定义一个OleDbCommandBuilder对象,用于协调DataSet的更改所自动生成的单表命令
Public mycmdbuildder As OleDbCommandBuilder
Public Function SQLOpera(ByVal str As String, ByVal table As String) 'str参数为查询语句,table为所要执行的表
Try
'定义一个存储当前行数的变量
Dim row As Integer = 0
'定义一个执行SQL命令的字符串变量
Dim Selectstring As String
Selectstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
'使用相对路径
Selectstring = Selectstring & Application.StartupPath() & "\Data\mydb.mdb"
mydap = New OleDbDataAdapter(str, Selectstring)
'清除数据集的所有表
mydataset.Clear()
mydataset.Tables.Clear()
'填充数据集
mydap.Fill(mydataset, table)
'获取数据集中的表
mytable = mydataset.Tables.Item(0)
myrow = mytable.Rows.Item(row)
Catch ex As Exception
End Try
Return Nothing
End Function
End Module
employee.vb中Button1代码
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tablename As String = "订单信息表"
Dim strr As String
strr = "select * from 订单信息表 where (订单编码='" & Trim(TextBox1.Text) & "')"
Commonmodule.SQLOpera(strr, tablename)
Dim count As Integer = Commonmodule.mytable.Rows.Count
If count <= 0 Then
MsgBox("不存在该订单!", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Information...")
Exit Sub
End If
TextBox2.Text = Commonmodule.myrow.Item(4).ToString
TextBox3.Text = Commonmodule.myrow.Item(5).ToString
TextBox4.Text = Commonmodule.myrow.Item(8).ToString
TextBox5.Text = Commonmodule.myrow.Item(9).ToString
End Sub