executiontenonquery连接属性尚未初始化

时间:2012-05-17 09:34:22

标签: visual-studio-2010

每次点击“保存”按钮时都会出现错误。这是什么意思?

谢谢你的任何回复..这是我的代码。;;;

Private Sub ButtonSave_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理ButtonSave.Click         如果con.State = ConnectionState.Closed那么             con.Open()         结束如果

    cmd.CommandText = "INSERT INTO tablephotometry(pCode, lampcode, costumer, proddate, line/shift, watts, volts, filam, base, basepos, lumen, life, atm, fuse, exp, type, testcode, testvolt, datestart, timestart, LNWatts1, LNWatts2, LNWatts3, LNWatts4, LNWatts5, LNLumen1, LNLumen2, LNLumen3, LNLumen4, LNLumen5, LNLPW1, LNLPW2, LNLPW3, LNLPW4, LNLPW5, RLWatts1, RLWatts2, RLWatts3, RLWatts4, RLWatts5, RLLumen1, RLLumen2, RLLumen3, RLLumen4, RLLumen5, LPWF1, LPWF2, LPWF3, LPWF4, LPWF5, InspectionTime1, InspectionTime2, InspectionTime3, InspectionTime4, InspectionTime5, InspectionDate1, InspectionDate2, InspectionDate3, InspectionDate4, InspectionDate5, TH1, TH2, TH3, TH4, TH5, EL1, EL2, EL3, EL4, EL5, Dispo1, Dispo2, Dispo3, Dispo4, Dispo5, CF1, CF2, CF3, CF4, CF5, Reason1, Reason2, Reason3, Reason4, Reason5, TorqueTest, 0Hour, EndOfLife, PFCPTime1, PFCPTime2, PFCPTime3, PFCPTime4, PFCPTime5, PFCPDate1, PFCPDate2, PFCPDate3, PFCPDate4, PFCPDate5, LNAve1, LNAve2, LNAve3, LNAve4, LNAve5, LNAve6, LNAve7, LNAve8, LNAve9, LNAve10, LNAve11, LNAve12, LNAve13, LNsd1, LNsd2, LNsd3, LNsd4, LNsd5, LNsd6, LNsd7, LNsd8, LNsd9, LNsd10, LNsd11, LNsd12, LNsd13) " & _
    "VALUES( " & TextBoxPCode.Text & "','" & TextBoxLampCode.Text & "','" & TextBoxCostumer.Text & "','" _
     & TextBoxProdDate.Text & "','" & TextBoxLS.Text & "','" & TextBoxWatts.Text & "','" & TextBoxVolt.Text & "', '" _
     & TextBoxFilam.Text & "','" & TextBoxBase.Text & "','" & TextBoxBPos.Text & "','" & TextBoxLumen.Text & "','" _
     & TextBoxLife.Text & "','" & TextBoxAtm.Text & "','" & TextBoxFuse.Text & "','" & TextBoxEXPONENT.Text & "','" _
     & TextBoxSampleSize.Text & "','" & TextBoxType.Text & "','" & TextBoxTCode.Text & "','" & TextBoxTVolt.Text & "','" _
     & TextBoxDStart.Text & "','" & TextBoxTStart.Text & "','" & TextBoxLNWatts1.Text & "','" & TextBoxLNWatts2.Text & "','" _
     & TextBoxLNWatts3.Text & "','" & TextBoxLNWatts4.Text & "','" & TextBoxLNWatts5.Text & "','" & TextBoxLNLumen1.Text & "','" _
     & TextBoxLNLumen3.Text & "','" & TextBoxLNLumen4.Text & "','" & TextBoxLNLumen5.Text & "','" & TextBoxLNLPW1.Text & "','" _
     & TextBoxLNLPW2.Text & "','" & TextBoxLNLPW3.Text & "','" & TextBoxLNLPW4.Text & "','" & TextBoxLNLPW5.Text & "','" _
     & TextBoxRLWatts1.Text & "','" & TextBoxRLWatts2.Text & "','" & TextBoxRLWatts3.Text & "','" & TextBoxRLWatts4.Text & "','" _
     & TextBoxRLWatts5.Text & "','" & TextBoxRLLumen1.Text & "','" & TextBoxRLLumen2.Text & "','" & TextBoxRLLumen3.Text & "','" _
     & TextBoxRLLumen4.Text & "','" & TextBoxRLLumen5.Text & "','" & TextBoxLPWF1.Text & "','" & TextBoxLPWF2.Text & "','" _
     & TextBoxLPWF3.Text & "','" & TextBoxLPWF4.Text & "','" & TextBoxLPWF5.Text & "','" & TextBoxInspectionTime1.Text & "','" _
     & TextBoxInspectionTime2.Text & "','" & TextBoxInspectionTime3.Text & "','" & TextBoxInspectionTime4.Text & "','" & TextBoxInspectionTime5.Text & "','" _
     & TextBoxInspectionDate1.Text & "','" & TextBoxInspectionDate2.Text & "','" & TextBoxInspectionDate3.Text & "','" & TextBoxInspectionDate4.Text & "','" _
     & TextBoxInspectionDate5.Text & "','" & TextBoxTH1.Text & "','" & TextBoxTH2.Text & "','" & TextBoxTH3.Text & "','" _
     & TextBoxTH4.Text & "','" & TextBoxTH5.Text & "','" & TextBoxEL1.Text & "','" & TextBoxEL2.Text & "','" _
     & TextBoxEL3.Text & "','" & TextBoxEL4.Text & "','" & TextBoxEL5.Text & "','" & TextBoxDispo1.Text & "','" _
     & TextBoxDispo2.Text & "','" & TextBoxDispo3.Text & "','" & TextBoxDispo4.Text & "','" & TextBoxDispo5.Text & "','" _
     & TextBoxCF1.Text & "','" & TextBoxCF2.Text & "','" & TextBoxCF3.Text & "','" & TextBoxCF4.Text & "','" _
     & TextBoxCF5.Text & "','" & TextBoxReason1.Text & "','" & TextBoxReason2.Text & "','" & TextBoxReason3.Text & "','" _
     & TextBoxReason4.Text & "','" & TextBoxReason5.Text & "','" & TextBoxLNAve1.Text & "','" & TextBoxLNAve2.Text & "','" _
     & TextBoxLNAve3.Text & "','" & TextBoxLNAve4.Text & "','" & TextBoxLNAve5.Text & "','" & TextBoxLNAve6.Text & "','" _
     & TextBoxLNAve7.Text & "','" & TextBoxLNAve8.Text & "','" & TextBoxLNAve9.Text & "','" & TextBoxLNAve10.Text & "','" _
     & TextBoxLNAve11.Text & "','" & TextBoxLNAve12.Text & "','" & TextBoxLNAve13.Text & "','" & TextBoxLNsd1.Text & "','" _
     & TextBoxLNsd2.Text & "','" & TextBoxLNsd3.Text & "','" & TextBoxLNsd4.Text & "','" & TextBoxLNsd5.Text & "','" _
     & TextBoxLNsd6.Text & "','" & TextBoxLNsd7.Text & "','" & TextBoxLNsd8.Text & "','" & TextBoxLNsd9.Text & "','" _
     & TextBoxLNsd10.Text & "','" & TextBoxLNsd11.Text & "','" & TextBoxLNsd12.Text & "','" & TextBoxLNsd13.Text & "','" _
     & TextBoxTorqueTest.Text & "','" & TextBox0Hour.Text & "','" & TextBoxEndOfLife.Text & "','" & TextBoxPFCPDate1.Text & "','" _
     & TextBoxPFCPDate2.Text & "','" & TextBoxPFCPDate3.Text & "','" & TextBoxPFCPDate4.Text & "','" & TextBoxPFCPDate5.Text & "','" _
     & TextBoxPFCPTime1.Text & "','" & TextBoxPFCPTime2.Text & "','" & TextBoxPFCPTime3.Text & "','" & TextBoxPFCPTime4.Text & "','" _
     & TextBoxPFCPTime5.Text & "','" & TextBoxBatchNum.Text & "'," con)

    cmd.ExecuteNonQuery()*************************i always got an error in this part////
    MessageBox.Show("Data Succesfully Added!")
    con.Close()
    RefreshData()
End Sub

1 个答案:

答案 0 :(得分:0)

它不会给出任何具体错误吗? 你可能想给我们这个错误。

你在第一个值参数中缺少单引号。

VALUES( " & TextBoxPCode.Text & "','

应该是

VALUES( '" & TextBoxPCode.Text & "','