2012-05-17 224 views
0

我每次點擊保存按鈕時都會出現該錯誤。那是什麼意思?executenonquery連接屬性尚未初始化

謝謝你的回覆。這是我的代碼。

私人小組ButtonSave_Click(BYVAL發件人爲System.Object的,BYVALË作爲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 

回答

0

它是否給出了具體的錯誤? 你可能想給我們提供那個錯誤。

雖然您在第一個值參數中缺少單引號。

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

應該

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

感謝嗶嘰,我試了一下。但我想出了這個錯誤:「NullReferenceExection了未處理」這是我在這一個私人小組RefreshData() 代碼如果不con.State = ConnectionState.Open然後 con.Open() 結束如果 昏暗的大作爲新的OleDb.OleDbDataAdapter(「SELECT ID as [ID],」&_ 「fname as [NAME],lname」&_ 「FROM asdf ORDER by ID」,con) da.Fill(ds.Tables(「 ASDF「)) ' ' 關閉連接 con.Close() 結束小組 –

+0

你會被AB把它粘貼到'cmd.CommandText'中,這樣我就可以看看它,看看有什麼不對。這很難看出來。 –

相關問題