使用in运算符时未将对象引用设置为实例对象

时间:2019-05-09 00:33:35

标签: vb.net

我尝试了这段代码,但无法正常工作,给我未设置实例对象的错误对象引用

 Dim cmd As New OleDbCommand("SELECT PT.PT_Name, PT.PT_Agey, PT.PT_Agem, PT.PT_Aged, PT.PT_Date, Result.PT_code, Result.Test_No, Tests.Test_Name, Result.Result, Result.test_ref,Result.test_unit, Result.test_comm, Result.test_date,Result.HorL, PT.PT_Gender, PT.fullname2, PT.age_sex2,PT.PT_Nikname, DR.Dr_Name,Tests.Test_Name,Tests.upnormalshow, Subcategory.Subcat_Name, Maincategory.Maincatname, labdetails.labnme, labdetails.labspecial, labdetails.labadress, labdetails.labphone, labdetails.labtime, labdetails.lablogo, labdetails.labprint, labdetails.labnameenglish, labdetails.labspecialenglish FROM labdetails, ((((PT INNER JOIN (Result INNER JOIN Tests ON Result.Test_No = Tests.Test_No) ON PT.PT_Code = Result.PT_code) INNER JOIN DR ON PT.DR_Code = DR.Dr_Code) INNER JOIN Gender ON (Tests.Test_No = Gender.Test_ID) AND (PT.ageperiod2 = Gender.PT_Gender)) INNER JOIN Subcategory ON Tests.Subcat_ID = Subcategory.Subcat_ID) INNER JOIN Maincategory ON Tests.Maincat_ID = Maincategory.Maincat_ID WHERE (((Result.PT_code)=@ptcode) AND  Tests.Test_No Not In (10,11,12,13,14,15,18,20,21,42,76,77,78,79,80,81,92) AND Tests.Test_No = @testno AND ((Result.recorded))=Yes) and Result.test_date=@tstdate and PT.PT_Date=@ptdate and Result.PT_ID=@ptid ORDER BY Result.Test_No;", con)
cmd.Parameters.Add("@ptcode", OleDbType.Integer).Value = CInt(Txtcode.Text)
'  cmd.Parameters.Add("@TextNo", OleDbType.Integer).Value = (DataGridView1(8, DataGridView1.SelectedRows(0).Index).Value)
cmd.Parameters.Add("@tstdate", OleDbType.Date).Value = DateTimePicker1.Value.ToString("dd/MM/yyyy")
cmd.Parameters.Add("@ptdate", OleDbType.Date).Value = DateTimePicker1.Value.ToString("MM/dd/yyyy")
cmd.Parameters.Add("@ptid", OleDbType.Integer).Value = CInt(Texid.Text)
For Each dgvRow As DataGridViewRow In DataGridView1.SelectedRows
    cmd.Parameters.Add("@testno", OleDbType.Integer).Value = CInt(dgvRow.Cells(8).Value)
Next

con.Open()
dt.Load(cmd.ExecuteReader)

con.Close()

0 个答案:

没有答案