用VS2019建的项目
VB.net webforms 链接ACC数据库一直有错误,但有找不到出错在哪?哪位高手能解决一下,感激不尽!
一直提示
[NullReferenceException: 未将对象引用设置到对象的实例。]
Dim count As Integer = Commonmodule.mytable.Rows.Count
这句出错了
这个是一个Commonmodule模块
Imports System.Data.OleDb
Module Commonmodule
Public mydap As OleDbDataAdapter
Public mydataset As DataSet = New DataSet
Public mytable As DataTable
Public myrow As DataRow
Public mycmdbuilder As OleDbCommandBuilder
Public Function SQLOpera(ByVal str As String, ByVal table As String)
Try
Dim row As Integer = 0
Dim selectstring As String
selectstring = "provider=Microsoft.ACE.OLEDB.12.0;Data Source="
selectstring = selectstring & "E:\程序\App_Data\biaojia.accd"
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
这个是webforms 代码
Public Class WebForm1
Inherits System.Web.UI.Page
Public currentrow As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox_Logname.Text = "" Then
MsgBox("请输入用户名!", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "提示")
TextBox_Logname.Focus()
Exit Sub
ElseIf TextBox_Logpw.Text = "" Then
MsgBox("请输入密码!", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "提示")
TextBox_Logpw.Focus()
Exit Sub
End If
Try
Dim tablename As String = "denglu"
Dim strr As String
strr = "select username,pwd from denglu where (username='" & TextBox_Logname.Text & "' and pwd='" & TextBox_Logpw.Text & "')"
Commonmodule.SQLOpera(strr, tablename)
Dim count As Integer = Commonmodule.mytable.Rows.Count
If count < 1 Then
MsgBox("密码或用户名错误!请输入正确的用户名和密码!", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "提示")
Else
Session("name") = TextBox_Logname.Text
Response.Redirect("~/App_prg/index.aspx")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
Commonmodule.mytable
这个在哪里定义的
它可能是Nothing,你没有装入数据