我是vb的新手,我在使用长查询的监控系统上工作
If frm_MonitoringReg.txtIDnumber.Text = String.Empty Or frm_MonitoringReg.txtAddress.Text = String.Empty Or frm_MonitoringReg.txtBirthPlace.Text = String.Empty Or frm_MonitoringReg.txtFirstName.Text = String.Empty Or frm_MonitoringReg.txtIDnumber.Text = String.Empty Or frm_MonitoringReg.txtLastName.Text = String.Empty Or frm_MonitoringReg.txtMiddleName.Text = String.Empty Or frm_MonitoringReg.cmbCivilStatus.SelectedIndex = 0 Or frm_MonitoringReg.cmbGender.SelectedIndex = 0 Then
MsgBox("Must Fill All Fields")
Else
Dim AccountDS, PersonDS As New DataSet
'Dim Command As New SqlCommand(SQLCon)
'Command.Open()
Dim cmdSelectPersonInfo As New SqlCommand("SELECT * FROM [186].[dbo].personInfo WHERE pIDnumber = @pIDnumber", Connection)
cmdSelectPersonInfo.CommandType = CommandType.Text
cmdSelectPersonInfo.Parameters.AddWithValue("@pIDnumber", frm_MonitoringReg.txtIDnumber.Text)
Dim dAdapterPerson As New SqlDataAdapter(cmdSelectPersonInfo)
dAdapterPerson.Fill(PersonDS)
If PersonDS.Tables(0).Rows.Count >= 1 Then
MsgBox("Person Information is already created")
Else
Dim cmdAddPersonInfo As New SqlCommand("INSERT INTO [186].[dbo].[personInfo] (pIDnumber, pLname, pFname, pMname, pAddress, " & _
"pGender, pBirthday, pBirthPlace, pCivilStatus, DeletedFlag, createBy, createDate,pWorking " & _
"pOccupation,pStudying,pTSchool ,pHEducation,pDisability,pYr,pPrecinct,pYrBahay,pKPaninirahan " & _
"pKPKanino,pKPUpa,pLTinitirhan,pLTukuyin,pKBahay,pKtukuyin,pMBahay,pMTukuyin,pMeralco,pMaynilad " & _
"pTelepono,pBKita,pGPamilya,pKapitbahay,pPalikuran,pPagluluto,pPTukuyin,pTubig,pTTukuyin,pIlaw " & _
"pITukuyin,pLTelevision,pLVideoke,pLSports,pLMusical,pLReading,pLMalling,pLHiking,pHAso " & _
"pHPusa,pHManok,pHBaboy,pHIba,pHBilang,pSKotse,pSVan,pSJeepney,pSTricycle,pSIba,pSIba,pKRadio,pKAudio,pKKaraoke " & _
"pKPiano,pKCellphone,pKTV,pKVideoP,pKCam,pKWood,pKKerosene,pKLPG,pKGas,pKEStove,pKERange,pKMicrowave " & _
"pKRef,pKFreezer,pKWashing,pKHeated,pKAircon,pKEFan,pKETank,pKEHeater,pKComputer,pKLaptop,pKSystem,pKFlatI) " & _
"VALUES (@IDnumber, @Lname, @Fname, @Mname, @Address, @Gender, @bDay, @bPlace, @CivilStat, @deletedFlag, @createBy, @createDate " & _
"@pWorking,@pOccupation,@pStudying,@pTSchool,@pHEducation,@pDisability,@pYr,@pPrecinct,@pYrBahay,@pKPaninirahan " & _
"@pKPKanino,@pKPUpa,@pLTinitirhan,@pLTukuyin,@pKBahay,@pKtukuyin,@pMBahay,@pMTukuyin,@pMeralco,@pMaynilad " & _
"@pTelepono,@pBKita,@pGPamilya,@pKapitbahay,@pPalikuran,@pPagluluto,@pPTukuyin,@pTubig,@pTTukuyin,@pIlaw " & _
"@pITukuyin,@pLTelevision,@pLVideoke,@pLSports,@pLMusical,@pLReading,@pLMalling,@pLHiking,@pHAso " & _
"@pHPusa,@pHManok,@pHBaboy,@pHIba,@pHBilang,@pSKotse,@pSVan,@pSJeepney,@pSTricycle,@pSIba,@pSIba,@pKRadio,@pKAudio,@pKKaraoke " & _
"@pKPiano,@pKCellphone,@pKTV,@pKVideoP,@pKCam,@pKWood,@pKKerosene,@pKLPG,@pKGas,@pKEStove,@pKERange,@pKMicrowave " & _
"@pKRef,@pKFreezer,@pKWashing,@pKHeated,@pKAircon,@pKEFan,@pKETank,@pKEHeater,@pKComputer,@pKLaptop,@pKSystem,@pKFlatI)", Connection)
cmdAddPersonInfo.CommandType = CommandType.Text
cmdAddPersonInfo.Parameters.AddWithValue("@IDnumber", frm_MonitoringReg.txtIDnumber.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@Lname", frm_MonitoringReg.txtLastName.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@Fname", frm_MonitoringReg.txtFirstName.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@Mname", frm_MonitoringReg.txtMiddleName.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@Address", frm_MonitoringReg.txtAddress.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@Gender", frm_MonitoringReg.cmbGender.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@bDay", frm_MonitoringReg.dtpBirthDay.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@bPlace", frm_MonitoringReg.txtBirthPlace.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@CivilStat", frm_MonitoringReg.cmbCivilStatus.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@deletedFlag", 0)
cmdAddPersonInfo.Parameters.AddWithValue("@createBy", LoginForm.txtUsername.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@createDate", Now.Date.ToString)
cmdAddPersonInfo.Parameters.AddWithValue("@pWorking", frm_MonitoringReg.chckWorking.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pOccupation", frm_MonitoringReg.txtOccupation)
cmdAddPersonInfo.Parameters.AddWithValue("@pStudying", frm_MonitoringReg.chckStudying.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pTSchool", frm_MonitoringReg.cmboTypeofSchool.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pHEducation", frm_MonitoringReg.cmboHighestEduc.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pDisability", frm_MonitoringReg.chckDisablity.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pYr", frm_MonitoringReg.txtYrofStay)
cmdAddPersonInfo.Parameters.AddWithValue("@pPrecinct", frm_MonitoringReg.txtPrecintNo)
cmdAddPersonInfo.Parameters.AddWithValue("@pYrBahay", frm_MonitoringReg.txttyr)
cmdAddPersonInfo.Parameters.AddWithValue("@pKPaninirahan", frm_MonitoringReg.cmboKatayuan.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKPKanino", frm_MonitoringReg.txtKanino)
cmdAddPersonInfo.Parameters.AddWithValue("@pKPUpa", frm_MonitoringReg.txtUpa)
cmdAddPersonInfo.Parameters.AddWithValue("@pLTinitirhan", frm_MonitoringReg.cmboLote.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pLTukuyin", frm_MonitoringReg.txtlTukuyin)
cmdAddPersonInfo.Parameters.AddWithValue("@pKBahay", frm_MonitoringReg.cmboBahay.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKtukuyin", frm_MonitoringReg.txtbTukuyin)
cmdAddPersonInfo.Parameters.AddWithValue("@pMBahay", frm_MonitoringReg.cmbomBahay.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pMTukuyin", frm_MonitoringReg.txtmTukuyin)
cmdAddPersonInfo.Parameters.AddWithValue("@pMeralco", frm_MonitoringReg.chckMeralco.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pMaynilad", frm_MonitoringReg.chckMaynilad.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pTelepono", frm_MonitoringReg.chckTelepono.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pBKita", frm_MonitoringReg.txtKita)
cmdAddPersonInfo.Parameters.AddWithValue("@pGPamilya", frm_MonitoringReg.txtGastos)
cmdAddPersonInfo.Parameters.AddWithValue("@pKapitbahay", frm_MonitoringReg.txtKapitbahay)
cmdAddPersonInfo.Parameters.AddWithValue("@pPalikuran", frm_MonitoringReg.cmboPalikuran.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pPagluluto", frm_MonitoringReg.cmboPagluluto.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pPTukuyin", frm_MonitoringReg.txtpTukuyin)
cmdAddPersonInfo.Parameters.AddWithValue("@pTubig", frm_MonitoringReg.cmboTubig.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pTTukuyin", frm_MonitoringReg.txttTukuyin.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pIlaw", frm_MonitoringReg.cmboIlaw.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pITukuyin", frm_MonitoringReg.txtiTukuyin.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pLTelevision", chckTelevision.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pLVideoke", chckVideoke.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pLSports", chckSports.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pLMusical", chckMusicalInstruments.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pLReading", chckReading.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pLMalling", chckMalling.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pLHiking", chckHiking.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pLReading", chckReading.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("@pHAso", txtAso.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pHPusa", txtPusa.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pHManok", txtManok.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pHBaboy", txtBaboy.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pHIba", TxtHIba.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pHBilang", txtHBilang.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pSKotse", txtkotse.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pSVan", txtVan.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pSJeepney", txtJeepney.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pSTricycle", txtTricycle.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pSIba", txtSIba.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pSBilang", txtSBilang.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKRadio", txtRadio.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKAudio", txtSystem.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKKaraoke", txtKaraoke.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKPiano", txtKeyboard.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKCellphone", txtCp.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKTV", txtTV.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKVideoP", txtVideoP.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKCam", txtCamcorder.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKWood", txtWood.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKKerosene", txtKerosene.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKLPG", txtStove.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKGas", txtGas.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKEStove", txtElectric.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKERange", txtElectricCooking.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKMicrowave", txtOven.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKRef", txtRef.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKFreezer", txtFreezer.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKWashing", txtWashing.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKHeated", txtDryer.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKAircon", txtAirCon.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKEFan", txtFan.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKETank", txtTank.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKEHeater", txtHeater.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKCompute", txtComputer.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKLaptop", txtLaptop.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKSystem", txtGameSystem.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKFlatI", txtFlatiron.Text)
Dim dAdapter As New SqlDataAdapter(cmdAddPersonInfo)
dAdapter.Fill(AccountDS)
MsgBox("Information Successfuly Added")
frm_MonitoringReg.Close()
Me.Close()
Monitoring.Show()
End If
End If
但是当我尝试保存它时,我遇到了错误
Dim dAdapter As New SqlDataAdapter(cmdAddPersonInfo)
dAdapter.Fill(AccountDS)
错误说"从对象类型System.Windows.Forms.TextBox到已知的托管提供者本机类型没有映射。"。我第一次尝试输入它成功输入的程序,但直到表格#34; createby"所以我试图找到它停在那里的原因,但我没有找到它,这个错误突然冒出来。我不知道该怎么做了。
答案 0 :(得分:1)
你真的应该考虑以不同的方式做一些事情。
但无论如何:你的问题是因为你遗漏了许多这些陈述的.Text
。您需要专门为这些行添加:
cmdAddPersonInfo.Parameters.AddWithValue("@pYr", frm_MonitoringReg.txtYrofStay)
cmdAddPersonInfo.Parameters.AddWithValue("@pPrecinct", frm_MonitoringReg.txtPrecintNo)
cmdAddPersonInfo.Parameters.AddWithValue("@pYrBahay", frm_MonitoringReg.txttyr)
cmdAddPersonInfo.Parameters.AddWithValue("@pKPaninirahan", frm_MonitoringReg.cmboKatayuan.Text)
cmdAddPersonInfo.Parameters.AddWithValue("@pKPKanino", frm_MonitoringReg.txtKanino)
cmdAddPersonInfo.Parameters.AddWithValue("@pKPUpa", frm_MonitoringReg.txtUpa)
cmdAddPersonInfo.Parameters.AddWithValue("@pMTukuyin", frm_MonitoringReg.txtmTukuyin)
cmdAddPersonInfo.Parameters.AddWithValue("@pBKita", frm_MonitoringReg.txtKita)
cmdAddPersonInfo.Parameters.AddWithValue("@pGPamilya", frm_MonitoringReg.txtGastos)
cmdAddPersonInfo.Parameters.AddWithValue("@pKapitbahay", frm_MonitoringReg.txtKapitbahay)
cmdAddPersonInfo.Parameters.AddWithValue("@pPTukuyin", frm_MonitoringReg.txtpTukuyin)
还有一些我错过了。