未将对象设置到实例化 超级紧急啊 拜托拜托~~请大神帮忙 在线等

griggles 2014-12-12 02:09:06
Imports System.Data.OleDb
Imports System.IO
Public Class studentManage
Dim objDs As New DataSet
Dim objTSTable As DataTable
Dim objDa As New OleDbDataAdapter
Dim whereStr As String
Dim DBconnectionStr = "provider=microsoft.jet.oledb.4.0;" & "data source=" + Application.StartupPath + "\data\aa.mdb"


Public Sub bindgridview(ByVal strXH As String)
Dim objConn As New OleDbConnection
Dim objComm As New OleDbCommand
objConn.ConnectionString = DBconnectionStr
objComm.CommandText = "select * from studentManage"
If Trim(strXH) <> "" Then
objComm.CommandText = objComm.CommandText & strXH
End If
objComm.Connection = objConn
objDa.SelectCommand = objComm
Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(objDa)
objConn.Open()
objDa.Fill(objDs, "studentManage")
objTSTable = objDs.Tables("studentManahe")
objConn.Close()
objDa.Fill(objTSTable)
DataGridView1.DataSource = objTSTable
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
whereStr = ""
If Trim(TextBox1.Text) <> "" Then
whereStr = "where 学号 like '%" + Trim(TextBox1.Text) + "%'"
End If
objTSTable.Clear()
bindgridview(whereStr)
Dim cn As OleDbConnection = New OleDbConnection(DBconnectionStr)
cn.Open()
Dim command As OleDbCommand = New OleDbCommand("select * from studentManage where学号 ='" + Trim(TextBox1.Text) + "'", cn)
Dim dr As OleDbDataReader = command.ExecuteReader
If (dr.Read()) Then
TextBox2.Text = dr("姓名").ToString()
If Trim(dr("性别")) = "女" Then
RadioButton2.Checked = True
End If
DateTimePicker1.Text = dr("出生日期").ToString()
End If
cn.Dispose()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "错误提示")
End Try
End Sub
End Class
...全文
202 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wind_cloud2011 2014-12-12
  • 打赏
  • 举报
回复

上述修改外,
  Dim objTSTable As  DataTable--->Dim objTSTable As New DataTable
不要这句  objTSTable.Clear() 这句就会有这个错误提示。
这样就OK了

wind_cloud2011 2014-12-12
  • 打赏
  • 举报
回复

"select * from studentManage where学号='" + Trim(TextBox1.Text) + "'"
wind_cloud2011 2014-12-12
  • 打赏
  • 举报
回复

语句有些问题,你仔细看看,要留空格,
"select * from studentManage where 学号 ='" + Trim(TextBox1.Text) + "'"
 whereStr = " where  学号 like '%" + Trim(TextBox1.Text) + "%'"

moonwrite 2014-12-12
  • 打赏
  • 举报
回复
如果楼上各位所回答的 当你学会调试后 以后再也不会来问:未将对象设置到实例化 的问题了
_Monkey_King 2014-12-12
  • 打赏
  • 举报
回复
粗略目测 组合完SQL是select * from studentManagewhere 学号 like '%" + Trim(TextBox1.Text) + "%' where和表名 黏在一起 null应该也就是数据没取到了好像也只有进行了这一个操作
bdmh 2014-12-12
  • 打赏
  • 举报
回复
报错,也会告诉你哪里代码出错,自己打个断点,不就知道谁是null值了
  • 打赏
  • 举报
回复
你可能没有学会使用vs的调试起。 把你的try...catch去掉,调试器自然会起作用,你自然就会自己动手调试程序。
xdashewan 2014-12-12
  • 打赏
  • 举报
回复
哪一句代码出错都不指明

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧