สอบถามเรื่องการเซฟข้อมูล หน่อยค่ะ มันเซฟไม่ได้T_T vb.net ค่า
ค่าไม่ถูกต้องครับ ไม่แน่ใจตว่ามีค่าว่างหรือเปล่าครับ
Date :
2011-04-04 11:59:27
By :
webmaster
อ๋อ มีค่าว่างค่ะ
อ๋อ จะให้มันเซฟค่าว่างได้อ่ะค่ะ
Date :
2011-04-04 12:51:41
By :
mayapopy
ไม่มีใครมาช่วยเลยT_T
Date :
2011-04-04 14:53:33
By :
mayapopy
ลองใส่ข้อมูลให้ครบทุกฟิล์ดที่อยู่บนฟอร์ม
แล้วบันทึกดู
ถ้าบันทึกได้ เป็นไปได้ว่า Column ที่เป็นตัวเลข มันไม่รับค่าสตริงว่าง (สตริงว่างกับ DBNull.Value ต่างกันอยู่นะครับ)
Date :
2011-04-04 15:21:19
By :
watcharop
เป็นไปตามที่คุณ หางอึ้งบอกเลย แล้วทำยังไงหรอ????
ประวัติการแก้ไข 2011-04-04 15:58:15
Date :
2011-04-04 15:50:02
By :
mayapopy
ก็คือ เราสร้างฐานข้อมูลเอาไว้ให้มันรับค่า เป็นตัวเลขน่ะค่ะ
แต่ว่าบางช่องที่เป็นตัวเลข มันไม่ต้องกรอกข้อมูลค่ะ มันก็เลยกลายเป็นค่าว่าง
แบบนี้ก่อนที่เราจะเซฟเราต้องให้มันตรวจสอบค่าในช่องนั้นก่อนว่าเป็นค่าว่างหรือเปล่า ถ้าเป็นค่าว่างก็ให้ไปแปลงค่าให้เป็น string ก่อนใช่ไหมคะ? เข้าใจถูกหรือเปล่า^^
Date :
2011-04-04 16:00:04
By :
mayapopy
ลืมบอกไปที่เราให้ฐานข้อมูลมันรับแต่ค่า ตัวเลข เพราะกันความผิดพลาดไปกรอกเป็น ตัวหนังสือน่ะค่ะ
แต่ก็มีเพื่อนบอกว่า ทำไมไม่ใช่วิธีตรวจสอบค่าเอา แล้วก็ให้มันเด้งข้อความให้กรอกเป็นตัวเลขเท่านั้น
เราก็คิดว่า อืมม.. น่าทำ แต่เราทำไม่เป็นอ่ะ
คือไม่รู้ว่า จะตรวจสอบค่าว่าเป็น ตัวหนังสือ หรือ ตัวเลขยังไง? ก็เลยใช้วิธีกำหนดในฐานข้อมูลเลย
เราทำผิดมาตั้งแต่ต้นเลยหรือเปล่า
Date :
2011-04-04 16:03:23
By :
mayapopy
ถ้า TextBox อันไหนไม่กรอกตัวเลข (เป็นสตริงว่าง) ก็ต้องใส่แบบนี้แทนมั้ง
cmd.Parameters.AddWithValue("NumberColumn",dbnull.Value)
(ผมชื่อ "หางอึ่ง" ไม้เอกนะครับ ไม่รู้คุณพิมพ์เป็นไม้โท รึเปล่า )
ประวัติการแก้ไข 2011-04-04 16:13:54
Date :
2011-04-04 16:11:51
By :
watcharop
ตรง "NumberColumn" ให้ใส่ชื่อ Column ใช่ไหมคะ เช่น รหัสไปรษณีย์ ก็เป็น "EmpPostalCode",dbnull.Value
แล้วก็ให้ต่อไปกับแถวบรรทัดสุดท้ายหรือเปล่าคะ
พอดีที่เป็นตัวเลขมันมีเยอะน่ะค่ะ
ส่วนชื่อ คุณ หางอึ่ง ขอโทษค่ะ เราเขียนผิด พอดีอ่านไม่ชัด^^
เดี๋ยวเอาโค้ดให้ดูดีกว่า(ยาวนะ)
Private Sub Addbtt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Addbtt.Click
Dim intnumrow As Integer
Dim sqlstr As String = "SELECT Count(*) FROM EmpProfile WHERE IdNumber = " & Me.IdNumbertxt.Text
cmd = New OleDbCommand(sqlstr, con)
intnumrow = cmd.ExecuteScalar()
If intnumrow > 0 Then
MsgBox("รหัสซ้ำกรุณากรอกใหม่")
Return
ElseIf IdNumbertxt.TextLength < 5 Then
MsgBox("กรอกรหัสพนักงานไม่ครบ 5 หลััก กรุณากรอกใหม่")
Return
ElseIf IdCardtxt.TextLength < 13 Then
MsgBox("กรอกรหัสบัตรประชาชนให้ถูกต้อง")
Return
Else
Dim sql As String = "INSERT INTO EmpProfile(IdNumber, EmpDate, EmpPosition, EmpStatus, " & _
"EmpFrontName, EmpLastName, EmpDateRegister, EmpNickName, EmpIdCard, EmpBirthDay, " & _
"EmpProvinceBorn, EmpAge, EmpHeight, EmpWeight, EmpRace, " & _
"EmpNationality, EmpReligion, EmpAddress, EmpRoad, EmpDistrict, EmpArea, " & _
"EmpProvince, EmpPostalCode, EmpTelephone, EmpMobile, EmpEmail, EmpLocation, " & _
"EmpCondition, EmpMarry, EmpFatherName, EmpFatherSurname, EmpFatherAge, EmpFatherCareer, " & _
"EmpMotherName, EmpMotherSurname, EmpMotherAge, EmpMotherCareer, EmpRelativesNumber, " & _
"EmpManAmount, EmpWomanAmount, EmpNumber, EmpOneName, EmpOneSurName, EmpOneAge, EmpOneCareer, " & _
"EmpTwoName, EmpTwoSurname, EmpTwoAge, EmpTwoCareer, EmpThreeName, EmpThreeSurname, EmpThreeAge, " & _
"EmpThreeCareer, EmpMarryName, EmpMarrySurname, EmpMarryAge, EmpMarryCareer, EmpNumberChild, " & _
"EmpSonAmount, EmpDaughterAmount, EmpSchool1, EmpBranch1, EmpSince1, EmpTo1, EmpSchool2, " & _
"EmpBranch2, EmpSince2, EmpTo2, EmpSchool3, EmpBranch3, EmpSince3, EmpTo3, EmpSchool4, EmpBranch4, " & _
"EmpSince4, EmpTo4, EmpSchool5, EmpBranch5, EmpSince5, EmpTo5, EmpOffice1, EmpOfficeAddress1, " & _
"EmpBegin1, EmpEnd1, EmpSumTime1, EmpPosition1, EmpSalary1, EmpReason1, EmpJobQuality1, EmpCommanderName1, EmpPhoneOffice1, " & _
"EmpOffice2, EmpOfficeAddress2, EmpBegin2, EmpEnd2, EmpSumTime2, EmpPosition2, " & _
"EmpSalary2, EmpReason2, EmpJobQuality2, EmpCommanderName2, EmpPhoneOffice2, EmpOffice3, EmpOfficeAddress3, " & _
"EmpBegin3, EmpEnd3, EmpSumTime3, EmpPosition3, EmpSalary3, EmpReason3, EmpJobQuality3, EmpCommanderName3, " & _
"EmpPhoneOffice3, EmpTrainningName1, EmpTrainBegin1, EmpTrainEnd1, EmpTrainPosition1, EmpTrainQuality1, " & _
"EmpTrainningName2, EmpTrainBegin2, EmpTrainEnd2, EmpTrainPosition2, EmpTrainQuality2, EmpSpeakThai, " & _
"EmpWriteThai, EmpReadThai, EmpSpeakEnglish, EmpWriteEnglish, EmpReadEnglish, EmpSpeakJapan, EmpWriteJapan, " & _
"EmpReadJapan, EmpSpeakChina, EmpWriteChina, EmpReadChina, EmpProgram1, EmpClassbox1, EmpProgram2, EmpClassbox2, " & _
"EmpProgram3, EmpClassbox3, EmpTypeWriterThai, EmpTypeWriterEnglish, EmpNoDriver1, EmpHaveDriver1, EmpNoDriver2, " & _
"EmpHaveDriver2, EmpSport1, EmpSport2, EmpSport3, EmpHobby1, EmpHobby2, EmpHobby3, EmpTalent, EmpYesNo1, EmpReasonProvince, " & _
"EmpOutsiderName1, EmpOutsiderSurname1, EmpOutsiderCareer1, EmpRelation1, EmpOutsiderAddress1, EmpOutsiderPhone1, " & _
"EmpOutsiderName2, EmpOutsiderSurname2, EmpOutsiderCareer2, EmpRelation2, EmpOutsiderAddress2, EmpOutsiderPhone2, " & _
"EmpQuaranterName, EmpQuaranterSurname, EmpQuaranterCareer, EmpRelation3, EmpQuaranterAddress, EmpQuaranterPhone, " & _
"EmpQuaranterOffice, EmpQuaranterPosition, EmpQuaranterOfficeAddress, EmpQuaranterOfficeAddressPhone, EmpYesNo2, " & _
"EmpRemark1, EmpInformation, EmpYesNo3, EmpRemark2, EmpYesNo4, EmpRelativeName, EmpRelativeSurname, EmpRelativePosition, " & _
"EmpRelation4, EmpYesNo5, EmpRemark4, EmpIntroduce, EmpSalary, EmpTimeSince, EmpTimeTo, EmpBank, EmpNoAccount, EmpPoint1, " & _
"EmpPoint2, EmpPoint3, EmpPoint4, EmpPoint5, EmpPoint6, EmpPoint7, EmpAddExam, EmpTimesLoan, EmpSumLoan, EmpLoan, EmpTimesWarn, " & _
"EmpTimesFine, EmpSumFine, EmpMistake1, EmpMistake2, EmpMistake3, EmpCheckOut, EmpReasonOut) " & _
"VALUES(@idn, @edate, @eposition, @estatus, @efrontname, @elastname, @edateregister, @enickname, " & _
"@eidcard, @ebirthday, @eprovinceborn, @eage, @eheight, @eweight, @erace, @enationality, " & _
"@ereligion, @eaddress, @eroad, @edistrict, @earea, @eprovince, @epostalcode, @etelephone, " & _
"@emobile, @eemail, @elocation, @econdition, @emarry, @efathername, @efathersurname, @efatherage, @efathercareer, " & _
"@emothername, @emothersurname, @emotherage, @emothercareer, @erelativesnumber, @emanamount, @ewomanamount, @enumber, " & _
"@eonename, @eonesurname, @eoneage, @eonecareer, @etwoname, @etwosurname, @etwoage, @etwocareer, @ethreename, @ethreesurname, " & _
"@ethreeage, @ethreecareer, @emarryname, @emarrysurname, @emarryage, @emarrycareer, @enumberchild, @esonamount, @edaughteramount, " & _
"@eschool1, @ebranch1, @esince1, @eto1, @eschool2, @ebranch2, @esince2, @eto2, @eschool3, @ebranch3, @esince3, @eto3, @eschool4, " & _
"@ebranch4, @esince4, @eto4, @eschool5, @ebranch5, @esince5, @eto5, @eoffice1, @eofficeaddress1, @ebegin1, @eend1, @esumtime1, " & _
"@eposition1, @esalary1, @ereason1, @ejobquality1, @ecommandername1, @ephoneoffice1, @eoffice2, @eofficeaddress2, @ebegin2, " & _
"@eend2, @esumtime2, @eposition2, @esalary2, @ereason2, @ejobquality2, @ecommandername2, @ephoneoffice2, @eoffice3, @eofficeaddress3, " & _
"@ebegin3, @eend3, @esumtime3, @eposition3, @esalary3, @ereason3, @ejobquality3, @ecommandername3, @ephoneoffice3, @etrainningname1, " & _
"@etrainbegin1, @etrainend1, @etrainposition1, @etrainquality1, @etrainningname2, @etrainbegin2, @etrainend2, @etrainposition2, " & _
"@etrainquality2, @espeakthai, @ewritethai, @ereadthai, @espeakenglish, @ewriteenglish, @ereadenglish, @espeakjapan, @ewritejapan, " & _
"@ereadjapan, @espeakchina, @ewritechina, @ereadchina, @eprogram1, @eclassbox1, @eprogram2, @eclassbox2, @eprogram3, @eclassbox3, " & _
"@etypewriterthai, @etypewriterenglish, @enodriver1, @ehavedriver1, @enodriver2, @ehavedriver2, @esport1, @esport2, @esport3, @ehobby1, " & _
"@ehobby2, @ehobby3, @etalent, @eyesno1, @ereasonprovince, @eoutsidername1, @eoutsidersurname1, @eoutsidercareer1, @erelation1, " & _
"@eoutsideraddress1, @eoutsiderphone1, @eoutsidername2, @eoutsidersurname2, @eoutsidercareer2, @erelation2, " & _
"@eoutsideraddress2, @eoutsiderphone2, @equarantername, @equarantersurname, @equarantercareer, @erelation3, @equaranteraddress, " & _
"@equaranterphone, @equaranteroffice, @equaranterposition, @equaranterofficeaddress, @equaranterofficeaddressphone, @eyesno2, " & _
"@eremark1, @einformation, @eyesno3, @eremark2, @eyesno4, @erelativename, @erelativesurname, @erelativeposition, @erelation4, " & _
"@eyesno5 , @eremark4, @eintroduce, @esalary, @etimesince, @etimeto, @ebank, @enoaccount, @epoint1 , @epoint2, @epoint3, @epoint4, " & _
"@epoint5, @epoint6, @epoint7, @eaddexam, @etimesloan, @esumloan, @eloan, @etimeswarn, @etimesfine, @esumfine, @emistake1, @emistake2, " & _
"@emistake3, @echeckOut, @ereasonout) "
cmd = New OleDbCommand(sql, con)
cmd.Parameters.AddWithValue("idn", IdNumbertxt.Text)
cmd.Parameters.AddWithValue("edate", Datetxt.Text)
cmd.Parameters.AddWithValue("eposition", Positiontxt.Text)
cmd.Parameters.AddWithValue("estatus", StatusBox.Text)
cmd.Parameters.AddWithValue("efrontname", FrontNametxt.Text)
cmd.Parameters.AddWithValue("elastname", LastNametxt.Text)
cmd.Parameters.AddWithValue("edateregister", DateRegistertxt.Text)
cmd.Parameters.AddWithValue("enickname", NickNametxt.Text)
cmd.Parameters.AddWithValue("eidcard", IdCardtxt.Text)
cmd.Parameters.AddWithValue("ebirthday", Birthdaytxt.Text)
cmd.Parameters.AddWithValue("eprovinceborn", ProvinceBorntxt.Text)
cmd.Parameters.AddWithValue("eage", Agetxt.Text)
cmd.Parameters.AddWithValue("eheight", Heighttxt.Text)
cmd.Parameters.AddWithValue("eweight", Weighttxt.Text)
cmd.Parameters.AddWithValue("erace", Racetxt.Text)
cmd.Parameters.AddWithValue("enationality", Nationalitytxt.Text)
cmd.Parameters.AddWithValue("ereligion", Religiontxt.Text)
cmd.Parameters.AddWithValue("eaddress", Addresstxt.Text)
cmd.Parameters.AddWithValue("eroad", Roadtxt.Text)
cmd.Parameters.AddWithValue("edistrict", Districttxt.Text)
cmd.Parameters.AddWithValue("earea", Areatxt.Text)
cmd.Parameters.AddWithValue("eprovince", Provincetxt.Text)
cmd.Parameters.AddWithValue("epostalcode", PostalCodetxt.Text)
cmd.Parameters.AddWithValue("etelephone", Telephonetxt.Text)
cmd.Parameters.AddWithValue("emobile", Mobiletxt.Text)
cmd.Parameters.AddWithValue("eemail", Emailtxt.Text)
cmd.Parameters.AddWithValue("elocation", Locationbox.Text)
cmd.Parameters.AddWithValue("econdition", Conditionbox.Text)
cmd.Parameters.AddWithValue("emarry", Marrybox.Text)
cmd.Parameters.AddWithValue("efathername", FatherNametxt.Text)
cmd.Parameters.AddWithValue("efathersurname", FatherSurnametxt.Text)
cmd.Parameters.AddWithValue("efatherage", FatherAgetxt.Text)
cmd.Parameters.AddWithValue("efathercareer", FatherCareertxt.Text)
cmd.Parameters.AddWithValue("emothername", MotherNametxt.Text)
cmd.Parameters.AddWithValue("emothersurname", MotherSurnametxt.Text)
cmd.Parameters.AddWithValue("emotherage", MotherAgetxt.Text)
cmd.Parameters.AddWithValue("emothercareer", MotherCareertxt.Text)
cmd.Parameters.AddWithValue("erelativesnumber", RelativesNumbertxt.Text)
cmd.Parameters.AddWithValue("emanamount", ManAmounttxt.Text)
cmd.Parameters.AddWithValue("ewomanamount", WomanAmounttxt.Text)
cmd.Parameters.AddWithValue("enumber", Numbertxt.Text)
cmd.Parameters.AddWithValue("eonename", OneNametxt.Text)
cmd.Parameters.AddWithValue("eonesurname", OneSurNametxt.Text)
cmd.Parameters.AddWithValue("eoneage", OneAgetxt.Text)
cmd.Parameters.AddWithValue("eonecareer", OneCareertxt.Text)
cmd.Parameters.AddWithValue("etwoname", TwoNametxt.Text)
cmd.Parameters.AddWithValue("etwosurname", TwoSurnametxt.Text)
cmd.Parameters.AddWithValue("etwoage", TwoAgetxt.Text)
cmd.Parameters.AddWithValue("etwocareer", TwoCareertxt.Text)
cmd.Parameters.AddWithValue("ethreename", ThreeNametxt.Text)
cmd.Parameters.AddWithValue("ethreesurname", ThreeSurnametxt.Text)
cmd.Parameters.AddWithValue("ethreeage", ThreeAgetxt.Text)
cmd.Parameters.AddWithValue("ethreecareer", ThreeCareertxt.Text)
cmd.Parameters.AddWithValue("emarryname", MarryNametxt.Text)
cmd.Parameters.AddWithValue("emarrysurname", MarrySurnametxt.Text)
cmd.Parameters.AddWithValue("emarryage", MarryAgetxt.Text)
cmd.Parameters.AddWithValue("emarrycareer", MarryCareertxt.Text)
cmd.Parameters.AddWithValue("enumberchild", NumberChildtxt.Text)
cmd.Parameters.AddWithValue("esonamount", SonAmounttxt.Text)
cmd.Parameters.AddWithValue("edaughteramount", DaughterAmounttxt.Text)
cmd.Parameters.AddWithValue("eschool1", School1txt.Text)
cmd.Parameters.AddWithValue("ebranch1", Branch1txt.Text)
cmd.Parameters.AddWithValue("esince1", Since1txt.Text)
cmd.Parameters.AddWithValue("eto1", To1txt.Text)
cmd.Parameters.AddWithValue("eschool2", School2txt.Text)
cmd.Parameters.AddWithValue("ebranch2", Branch2txt.Text)
cmd.Parameters.AddWithValue("esince2", Since2txt.Text)
cmd.Parameters.AddWithValue("eto2", To2txt.Text)
cmd.Parameters.AddWithValue("eschool3", School3txt.Text)
cmd.Parameters.AddWithValue("ebranch3", Branch3txt.Text)
cmd.Parameters.AddWithValue("esince3", Since3txt.Text)
cmd.Parameters.AddWithValue("eto3", To3txt.Text)
cmd.Parameters.AddWithValue("eschool4", School4txt.Text)
cmd.Parameters.AddWithValue("ebranch4", Branch4txt.Text)
cmd.Parameters.AddWithValue("esince4", Since4txt.Text)
cmd.Parameters.AddWithValue("eto4", To4txt.Text)
cmd.Parameters.AddWithValue("eschool5", School5txt.Text)
cmd.Parameters.AddWithValue("ebranch5", Branch5txt.Text)
cmd.Parameters.AddWithValue("esince5", Since5txt.Text)
cmd.Parameters.AddWithValue("eto5", To5txt.Text)
cmd.Parameters.AddWithValue("eoffice1", Office1txt.Text)
cmd.Parameters.AddWithValue("eofficeaddress1", OfficeAddress1txt.Text)
cmd.Parameters.AddWithValue("ebegin1", Begin1txt.Text)
cmd.Parameters.AddWithValue("eend1", End1txt.Text)
cmd.Parameters.AddWithValue("esumtime1", SumTime1txt.Text)
cmd.Parameters.AddWithValue("eposition1", Position1txt.Text)
cmd.Parameters.AddWithValue("esalary1", Salary1txt.Text)
cmd.Parameters.AddWithValue("ereason1", Reason1txt.Text)
cmd.Parameters.AddWithValue("ejobquality1", JobQuality1txt.Text)
cmd.Parameters.AddWithValue("ecommandername1", CommanderName1txt.Text)
cmd.Parameters.AddWithValue("ephoneoffice1", PhoneOffice1txt.Text)
cmd.Parameters.AddWithValue("eoffice2", Office2txt.Text)
cmd.Parameters.AddWithValue("eofficeaddress2", OfficeAddress2txt.Text)
cmd.Parameters.AddWithValue("ebegin2", Begin2txt.Text)
cmd.Parameters.AddWithValue("eend2", End2txt.Text)
cmd.Parameters.AddWithValue("esumtime2", SumTime2txt.Text)
cmd.Parameters.AddWithValue("eposition2", Position2txt.Text)
cmd.Parameters.AddWithValue("esalary2", Salary2txt.Text)
cmd.Parameters.AddWithValue("ereason2", Reason2txt.Text)
cmd.Parameters.AddWithValue("ejobquality2", JobQuality2txt.Text)
cmd.Parameters.AddWithValue("ecommandername2", CommanderName2txt.Text)
cmd.Parameters.AddWithValue("ephoneoffice2", PhoneOffice2txt.Text)
cmd.Parameters.AddWithValue("eoffice3", Office3txt.Text)
cmd.Parameters.AddWithValue("eofficeaddress3", OfficeAddress3txt.Text)
cmd.Parameters.AddWithValue("ebegin3", Begin3txt.Text)
cmd.Parameters.AddWithValue("eend3", End3txt.Text)
cmd.Parameters.AddWithValue("esumtime3", SumTime3txt.Text)
cmd.Parameters.AddWithValue("eposition3", Position3txt.Text)
cmd.Parameters.AddWithValue("esalary3", Salary3txt.Text)
cmd.Parameters.AddWithValue("ereason3", Reason3txt.Text)
cmd.Parameters.AddWithValue("ejobquality3", JobQuality3txt.Text)
cmd.Parameters.AddWithValue("ecommandername3", CommanderName3txt.Text)
cmd.Parameters.AddWithValue("ephoneoffice3", PhoneOffice3txt.Text)
cmd.Parameters.AddWithValue("etrainningname1", TrainningName1txt.Text)
cmd.Parameters.AddWithValue("etrainbegin1", TrainBegin1txt.Text)
cmd.Parameters.AddWithValue("etrainend1", TrainEnd1txt.Text)
cmd.Parameters.AddWithValue("etrainposition1", TrainPosition1txt.Text)
cmd.Parameters.AddWithValue("etrainquality1", TrainQuality1txt.Text)
cmd.Parameters.AddWithValue("etrainningname2", TrainningName2txt.Text)
cmd.Parameters.AddWithValue("etrainbegin2", TrainBegin2txt.Text)
cmd.Parameters.AddWithValue("etrainend2", TrainEnd2txt.Text)
cmd.Parameters.AddWithValue("etrainposition2", TrainPosition2txt.Text)
cmd.Parameters.AddWithValue("etrainquality2", TrainQuality2txt.Text)
cmd.Parameters.AddWithValue("espeakthai", SpeakThaibox.Text)
cmd.Parameters.AddWithValue("ewritethai", WriteThaibox.Text)
cmd.Parameters.AddWithValue("ereadthai", ReadThaibox.Text)
cmd.Parameters.AddWithValue("espeakenglish", SpeakEnglishbox.Text)
cmd.Parameters.AddWithValue("ewriteenglish", WriteEnglishbox.Text)
cmd.Parameters.AddWithValue("ereadenglish", ReadEnglishbox.Text)
cmd.Parameters.AddWithValue("espeakjapan", SpeakJapanbox.Text)
cmd.Parameters.AddWithValue("ewritejapan", WriteJapanbox.Text)
cmd.Parameters.AddWithValue("ereadjapan", ReadJapanbox.Text)
cmd.Parameters.AddWithValue("espeakchina", SpeakChinabox.Text)
cmd.Parameters.AddWithValue("ewritechina", WriteChinabox.Text)
cmd.Parameters.AddWithValue("ereadchina", ReadChinabox.Text)
cmd.Parameters.AddWithValue("eprogram1", Program1txt.Text)
cmd.Parameters.AddWithValue("eclassbox1", Classbox1.Text)
cmd.Parameters.AddWithValue("eprogram2", Program2txt.Text)
cmd.Parameters.AddWithValue("eclassbox2", Classbox2.Text)
cmd.Parameters.AddWithValue("eprogram3", Program3txt.Text)
cmd.Parameters.AddWithValue("eclassbox3", Classbox3.Text)
cmd.Parameters.AddWithValue("etypewriterthai", TypeWriterThaitxt.Text)
cmd.Parameters.AddWithValue("etypewriterenglish", TypeWriterEnglishtxt.Text)
cmd.Parameters.AddWithValue("enodriver1", NoDriver1txt.Text)
cmd.Parameters.AddWithValue("ehavedriver1", HaveDriverbox1.Text)
cmd.Parameters.AddWithValue("enodriver2", NoDriver2txt.Text)
cmd.Parameters.AddWithValue("ehavedriver2", HaveDriverbox2.Text)
cmd.Parameters.AddWithValue("esport1", Sport1txt.Text)
cmd.Parameters.AddWithValue("esport2", Sport2txt.Text)
cmd.Parameters.AddWithValue("esport3", Sport3txt.Text)
cmd.Parameters.AddWithValue("ehobby1", Hobby1txt.Text)
cmd.Parameters.AddWithValue("ehobby2", Hobby2txt.Text)
cmd.Parameters.AddWithValue("ehobby3", Hobby3txt.Text)
cmd.Parameters.AddWithValue("etalent", Talenttxt.Text)
cmd.Parameters.AddWithValue("eyesno1", YesNo1box.Text)
cmd.Parameters.AddWithValue("ereasonprovince", ReasonProvincetxt.Text)
cmd.Parameters.AddWithValue("eoutsidername1", OutsiderName1txt.Text)
cmd.Parameters.AddWithValue("eoutsidersurname1", OutsiderSurname1txt.Text)
cmd.Parameters.AddWithValue("eoutsidercareer1", OutsiderCareer1txt.Text)
cmd.Parameters.AddWithValue("erelation1", Relation1txt.Text)
cmd.Parameters.AddWithValue("eoutsideraddress1", OutsiderAddress1txt.Text)
cmd.Parameters.AddWithValue("eoutsiderphone1", OutsiderPhone1txt.Text)
cmd.Parameters.AddWithValue("eoutsidername2", OutsiderName2txt.Text)
cmd.Parameters.AddWithValue("eoutsidersurname2", OutsiderSurname2txt.Text)
cmd.Parameters.AddWithValue("eoutsidercareer2", OutsiderCareer2txt.Text)
cmd.Parameters.AddWithValue("erelation2", Relation2txt.Text)
cmd.Parameters.AddWithValue("eoutsideraddress2", OutsiderAddress2txt.Text)
cmd.Parameters.AddWithValue("eoutsiderphone2", OutsiderPhone2txt.Text)
cmd.Parameters.AddWithValue("equarantername", QuaranterNametxt.Text)
cmd.Parameters.AddWithValue("equarantersurname", QuaranterSurNametxt.Text)
cmd.Parameters.AddWithValue("equarantercareer", QuaranterCareertxt.Text)
cmd.Parameters.AddWithValue("erelation3", Relation3txt.Text)
cmd.Parameters.AddWithValue("equaranteraddress", QuaranterAddresstxt.Text)
cmd.Parameters.AddWithValue("equaranterphone", QuaranterPhonetxt.Text)
cmd.Parameters.AddWithValue("equaranteroffice", QuaranterOfficetxt.Text)
cmd.Parameters.AddWithValue("equaranterposition", QuaranterPositiontxt.Text)
cmd.Parameters.AddWithValue("equaranterofficeaddress", QuaranterOfficeAddresstxt.Text)
cmd.Parameters.AddWithValue("equaranterofficeaddressphone", QuaranterOfficeAddressPhonetxt.Text)
cmd.Parameters.AddWithValue("eyesno2", YesNo2box.Text)
cmd.Parameters.AddWithValue("eremark1", Remark1txt.Text)
cmd.Parameters.AddWithValue("einformation", Informationtxt.Text)
cmd.Parameters.AddWithValue("eyesno3", YesNo3box.Text)
cmd.Parameters.AddWithValue("eremark2", Remark2txt.Text)
cmd.Parameters.AddWithValue("eyesno4", YesNo4box.Text)
cmd.Parameters.AddWithValue("erelativename", RelativeNametxt.Text)
cmd.Parameters.AddWithValue("erelativesurname", RelativeSurnametxt.Text)
cmd.Parameters.AddWithValue("erelativeposition", RelativePositiontxt.Text)
cmd.Parameters.AddWithValue("erelation4", Relation4txt.Text)
cmd.Parameters.AddWithValue("eyesno5", YesNo5box.Text)
cmd.Parameters.AddWithValue("eremark4", Remark3txt.Text)
cmd.Parameters.AddWithValue("eintroduce", Introducetxt.Text)
cmd.Parameters.AddWithValue("esalary", Salarytxt.Text)
cmd.Parameters.AddWithValue("etimesince", TimeSincebox.Text)
cmd.Parameters.AddWithValue("etimeto", TimeTobox.Text)
cmd.Parameters.AddWithValue("ebank", Bankbox.Text)
cmd.Parameters.AddWithValue("enoaccount", NoAccounttxt.Text)
cmd.Parameters.AddWithValue("epoint1", Point1txt.Text)
cmd.Parameters.AddWithValue("epoint2", Point2txt.Text)
cmd.Parameters.AddWithValue("epoint3", Point3txt.Text)
cmd.Parameters.AddWithValue("epoint4", Point4txt.Text)
cmd.Parameters.AddWithValue("epoint5", Point5txt.Text)
cmd.Parameters.AddWithValue("epoint6", Point6txt.Text)
cmd.Parameters.AddWithValue("epoint7", Point7txt.Text)
cmd.Parameters.AddWithValue("eaddexam", AddExamtxt.Text)
cmd.Parameters.AddWithValue("etimesloan", TimesLoantxt.Text)
cmd.Parameters.AddWithValue("esumloan", SumLoantxt.Text)
cmd.Parameters.AddWithValue("eloan", Loantxt.Text)
cmd.Parameters.AddWithValue("etimeswarn", TimesWarntxt.Text)
cmd.Parameters.AddWithValue("etimesfine", TimesFinetxt.Text)
cmd.Parameters.AddWithValue("esumfine", SumFinetxt.Text)
cmd.Parameters.AddWithValue("emistake1", Mistake1txt.Text)
cmd.Parameters.AddWithValue("emistake2", Mistake2txt.Text)
cmd.Parameters.AddWithValue("emistake3", Mistake3txt.Text)
cmd.Parameters.AddWithValue("echeckOut", OutOfficebox.Text)
cmd.Parameters.AddWithValue("ereasonout", ReasonOuttxt.Text)
cmd.Parameters.AddWithValue("EmpPostalCode", DBNull.Value) <======= แบบนี้หรือเปล่า
Dim affect As Integer = cmd.ExecuteNonQuery()
If (affect < 1) Then
MsgBox("เกิดข้อผิดพลาด" & vbNewLine & "ไม่สามารถเพิ่มข้อมูลได้")
Else
MsgBox("เพิ่มข้อมูลเรียบร้อยแล้ว")
End If
'ClearBindings()
'EmpInfo()
'If (namebox.Items.Count > 0) Then
' namebox.SelectedIndex = 0
'End If
End If
End Sub
Date :
2011-04-04 16:25:55
By :
mayapopy
1. EmpPostalCode เป็นฟิล์ด Integer?
2. โปรแกรมจะ Error ถ้าใส่ EmpPostalCodetxt เป็นข้อความที่ไม่ใช่ตัวเลข Integer
Code (VB.NET)
cmd.Parameters.Add("@EmpPostalCode", SqlDbType.Integer, IIf(EmpPostalCodetxt.Text<>"",CTYPE(EmpPostalCodetxt.Text,Integer),DBNull.Value))
Date :
2011-04-04 16:45:55
By :
watcharop
ฟิล์ดที่เก็บข้อมูลเบอร์โทร เบอร์แฟ็กซื รหัสไปรษณีย์ ไม่รู้ว่าคุณสร้าง Column เก็บข้อมูลเป็น Text หรือ Number
จากประสบการณ์ เก็บเป็น Text จะดีกว่าครับ
ถ้าโปรเจ็คนี้เก็บเป็น Number อยู่ก็ปล่อยไปก่อนก็ได้ครับ
เอาไว้โปรเจ็คหน้าค่อยว่ากันใหม่
Date :
2011-04-04 16:52:59
By :
watcharop
อ๋อ ใช่ เรากำหนดไว้ใน access แบบนี้
เราต้องเปลี่ยน SqlDbType เป็น OleDbType ใช่ไหมคะ?
(ลืมบอกไปว่าใช้ Access ขอโทษค่ะ)
Date :
2011-04-04 16:53:34
By :
mayapopy
อ๋อ ค่ะ เดี๋ยวคราวหน้าจะเก็บเป็น Text ให้หมดค่ะ (เปลี่ยนตอนนี้ไม่ทันหรอคะ?)
ถ้าเปลี่ยนเป็น Text ต้องหา โค้ดที่ตรวจสอบว่า ให้ใส่ตัวเลข
ในหนังสือน่าจะมี เดี๋ยววันนี้กลับไปหาก่อน^^
Date :
2011-04-04 16:55:21
By :
mayapopy
อ๋อ ขอบคุณค่า
ปล.จริงๆก็เหนื่อยตลอดเวลาอยู่แล้วนะ เวลาเจอปัญหาเนี๊ย แต่พอแก้ได้แล้วสนุก เลยชอบ (ประสาทม่ะ^^)
เดี๋ยวกลับก่อนนะคะ เดี๋ยวพรุ่งนี้มาดูใหม่
ไม่รู้จะแก้ได้หรือเปล่า
ขอบคุณล่วงหน้าค่ะ^^
Date :
2011-04-04 17:05:36
By :
mayapopy
' จขกท ไม่ได้ขอ แต่อยากแถม
' SaveData ถูกเรียกเมื่อเรากดปุ่มบันทึกข้อมูล
ตัวอย่างการใช้ OleDbAdapter, OleDbCommandBuilder เพื่อบันทึกข้อมูล
Public Sub SaveData()
Using cn As New OleDbConnection("ConnectString เพื่อเปิดฐานข้อมูล Access")
cn.Open()
Dim da As New OleDbDataAdapter()
da.SelectCommand = New OleDbCommand("SELECT * FROM EmpProfile", cn)
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)
cb.ConflictOption = ConflictOption.OverwriteChanges
da.InsertCommand = cb.GetInsertCommand(True)
da.InsertCommand.Connection = cn
da.UpdateCommand = cb.GetUpdateCommand(True)
da.UpdateCommand.Connection = cn
da.DeleteCommand = cb.GetDeleteCommand(True)
da.DeleteCommand.Connection = cn
da.Update(YourDataSetInstance, "EmpProfile")
End Using
End Sub
ประวัติการแก้ไข 2011-04-04 17:24:26 2011-04-04 17:25:05
Date :
2011-04-04 17:23:55
By :
watcharop
โค้ดนี้ไว้ใช้บันทึกข้อมูลหรอคะ
พอดีทำบันทึกข้อมูลไปแล้วอ่ะ ยาวด้วย- -
Private Sub Addbtt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Addbtt.Click
Dim intnumrow As Integer
Dim sqlstr As String = "SELECT Count(*) FROM EmpProfile WHERE IdNumber = " & Me.IdNumbertxt.Text
cmd = New OleDbCommand(sqlstr, con)
intnumrow = cmd.ExecuteScalar()
If intnumrow > 0 Then
MsgBox("รหัสซ้ำกรุณากรอกใหม่")
Return
ElseIf IdNumbertxt.TextLength < 5 Then
MsgBox("กรอกรหัสพนักงานไม่ครบ 5 หลััก กรุณากรอกใหม่")
Return
ElseIf IdCardtxt.TextLength < 13 Then
MsgBox("กรอกรหัสบัตรประชาชนให้ถูกต้อง")
Return
Else
Dim sql As String = "INSERT INTO EmpProfile(IdNumber, EmpDate, EmpPosition, EmpStatus, " & _
"EmpFrontName, EmpLastName, EmpDateRegister, EmpNickName, EmpIdCard, EmpBirthDay, " & _
"EmpProvinceBorn, EmpAge, EmpHeight, EmpWeight, EmpRace, " & _
"EmpNationality, EmpReligion, EmpAddress, EmpRoad, EmpDistrict, EmpArea, " & _
"EmpProvince, EmpPostalCode, EmpTelephone, EmpMobile, EmpEmail, EmpLocation, " & _
"EmpCondition, EmpMarry, EmpFatherName, EmpFatherSurname, EmpFatherAge, EmpFatherCareer, " & _
"EmpMotherName, EmpMotherSurname, EmpMotherAge, EmpMotherCareer, EmpRelativesNumber, " & _
"EmpManAmount, EmpWomanAmount, EmpNumber, EmpOneName, EmpOneSurName, EmpOneAge, EmpOneCareer, " & _
"EmpTwoName, EmpTwoSurname, EmpTwoAge, EmpTwoCareer, EmpThreeName, EmpThreeSurname, EmpThreeAge, " & _
"EmpThreeCareer, EmpMarryName, EmpMarrySurname, EmpMarryAge, EmpMarryCareer, EmpNumberChild, " & _
"EmpSonAmount, EmpDaughterAmount, EmpSchool1, EmpBranch1, EmpSince1, EmpTo1, EmpSchool2, " & _
"EmpBranch2, EmpSince2, EmpTo2, EmpSchool3, EmpBranch3, EmpSince3, EmpTo3, EmpSchool4, EmpBranch4, " & _
"EmpSince4, EmpTo4, EmpSchool5, EmpBranch5, EmpSince5, EmpTo5, EmpOffice1, EmpOfficeAddress1, " & _
"EmpBegin1, EmpEnd1, EmpSumTime1, EmpPosition1, EmpSalary1, EmpReason1, EmpJobQuality1, EmpCommanderName1, EmpPhoneOffice1, " & _
"EmpOffice2, EmpOfficeAddress2, EmpBegin2, EmpEnd2, EmpSumTime2, EmpPosition2, " & _
"EmpSalary2, EmpReason2, EmpJobQuality2, EmpCommanderName2, EmpPhoneOffice2, EmpOffice3, EmpOfficeAddress3, " & _
"EmpBegin3, EmpEnd3, EmpSumTime3, EmpPosition3, EmpSalary3, EmpReason3, EmpJobQuality3, EmpCommanderName3, " & _
"EmpPhoneOffice3, EmpTrainningName1, EmpTrainBegin1, EmpTrainEnd1, EmpTrainPosition1, EmpTrainQuality1, " & _
"EmpTrainningName2, EmpTrainBegin2, EmpTrainEnd2, EmpTrainPosition2, EmpTrainQuality2, EmpSpeakThai, " & _
"EmpWriteThai, EmpReadThai, EmpSpeakEnglish, EmpWriteEnglish, EmpReadEnglish, EmpSpeakJapan, EmpWriteJapan, " & _
"EmpReadJapan, EmpSpeakChina, EmpWriteChina, EmpReadChina, EmpProgram1, EmpClassbox1, EmpProgram2, EmpClassbox2, " & _
"EmpProgram3, EmpClassbox3, EmpTypeWriterThai, EmpTypeWriterEnglish, EmpNoDriver1, EmpHaveDriver1, EmpNoDriver2, " & _
"EmpHaveDriver2, EmpSport1, EmpSport2, EmpSport3, EmpHobby1, EmpHobby2, EmpHobby3, EmpTalent, EmpYesNo1, EmpReasonProvince, " & _
"EmpOutsiderName1, EmpOutsiderSurname1, EmpOutsiderCareer1, EmpRelation1, EmpOutsiderAddress1, EmpOutsiderPhone1, " & _
"EmpOutsiderName2, EmpOutsiderSurname2, EmpOutsiderCareer2, EmpRelation2, EmpOutsiderAddress2, EmpOutsiderPhone2, " & _
"EmpQuaranterName, EmpQuaranterSurname, EmpQuaranterCareer, EmpRelation3, EmpQuaranterAddress, EmpQuaranterPhone, " & _
"EmpQuaranterOffice, EmpQuaranterPosition, EmpQuaranterOfficeAddress, EmpQuaranterOfficeAddressPhone, EmpYesNo2, " & _
"EmpRemark1, EmpInformation, EmpYesNo3, EmpRemark2, EmpYesNo4, EmpRelativeName, EmpRelativeSurname, EmpRelativePosition, " & _
"EmpRelation4, EmpYesNo5, EmpRemark4, EmpIntroduce, EmpSalary, EmpTimeSince, EmpTimeTo, EmpBank, EmpNoAccount, EmpPoint1, " & _
"EmpPoint2, EmpPoint3, EmpPoint4, EmpPoint5, EmpPoint6, EmpPoint7, EmpAddExam, EmpTimesLoan, EmpSumLoan, EmpLoan, EmpTimesWarn, " & _
"EmpTimesFine, EmpSumFine, EmpMistake1, EmpMistake2, EmpMistake3, EmpCheckOut, EmpReasonOut) " & _
"VALUES(@idn, @edate, @eposition, @estatus, @efrontname, @elastname, @edateregister, @enickname, " & _
"@eidcard, @ebirthday, @eprovinceborn, @eage, @eheight, @eweight, @erace, @enationality, " & _
"@ereligion, @eaddress, @eroad, @edistrict, @earea, @eprovince, @epostalcode, @etelephone, " & _
"@emobile, @eemail, @elocation, @econdition, @emarry, @efathername, @efathersurname, @efatherage, @efathercareer, " & _
"@emothername, @emothersurname, @emotherage, @emothercareer, @erelativesnumber, @emanamount, @ewomanamount, @enumber, " & _
"@eonename, @eonesurname, @eoneage, @eonecareer, @etwoname, @etwosurname, @etwoage, @etwocareer, @ethreename, @ethreesurname, " & _
"@ethreeage, @ethreecareer, @emarryname, @emarrysurname, @emarryage, @emarrycareer, @enumberchild, @esonamount, @edaughteramount, " & _
"@eschool1, @ebranch1, @esince1, @eto1, @eschool2, @ebranch2, @esince2, @eto2, @eschool3, @ebranch3, @esince3, @eto3, @eschool4, " & _
"@ebranch4, @esince4, @eto4, @eschool5, @ebranch5, @esince5, @eto5, @eoffice1, @eofficeaddress1, @ebegin1, @eend1, @esumtime1, " & _
"@eposition1, @esalary1, @ereason1, @ejobquality1, @ecommandername1, @ephoneoffice1, @eoffice2, @eofficeaddress2, @ebegin2, " & _
"@eend2, @esumtime2, @eposition2, @esalary2, @ereason2, @ejobquality2, @ecommandername2, @ephoneoffice2, @eoffice3, @eofficeaddress3, " & _
"@ebegin3, @eend3, @esumtime3, @eposition3, @esalary3, @ereason3, @ejobquality3, @ecommandername3, @ephoneoffice3, @etrainningname1, " & _
"@etrainbegin1, @etrainend1, @etrainposition1, @etrainquality1, @etrainningname2, @etrainbegin2, @etrainend2, @etrainposition2, " & _
"@etrainquality2, @espeakthai, @ewritethai, @ereadthai, @espeakenglish, @ewriteenglish, @ereadenglish, @espeakjapan, @ewritejapan, " & _
"@ereadjapan, @espeakchina, @ewritechina, @ereadchina, @eprogram1, @eclassbox1, @eprogram2, @eclassbox2, @eprogram3, @eclassbox3, " & _
"@etypewriterthai, @etypewriterenglish, @enodriver1, @ehavedriver1, @enodriver2, @ehavedriver2, @esport1, @esport2, @esport3, @ehobby1, " & _
"@ehobby2, @ehobby3, @etalent, @eyesno1, @ereasonprovince, @eoutsidername1, @eoutsidersurname1, @eoutsidercareer1, @erelation1, " & _
"@eoutsideraddress1, @eoutsiderphone1, @eoutsidername2, @eoutsidersurname2, @eoutsidercareer2, @erelation2, " & _
"@eoutsideraddress2, @eoutsiderphone2, @equarantername, @equarantersurname, @equarantercareer, @erelation3, @equaranteraddress, " & _
"@equaranterphone, @equaranteroffice, @equaranterposition, @equaranterofficeaddress, @equaranterofficeaddressphone, @eyesno2, " & _
"@eremark1, @einformation, @eyesno3, @eremark2, @eyesno4, @erelativename, @erelativesurname, @erelativeposition, @erelation4, " & _
"@eyesno5 , @eremark4, @eintroduce, @esalary, @etimesince, @etimeto, @ebank, @enoaccount, @epoint1 , @epoint2, @epoint3, @epoint4, " & _
"@epoint5, @epoint6, @epoint7, @eaddexam, @etimesloan, @esumloan, @eloan, @etimeswarn, @etimesfine, @esumfine, @emistake1, @emistake2, " & _
"@emistake3, @echeckOut, @ereasonout) "
cmd = New OleDbCommand(sql, con)
cmd.Parameters.AddWithValue("idn", IdNumbertxt.Text)
cmd.Parameters.AddWithValue("edate", Datetxt.Text)
cmd.Parameters.AddWithValue("eposition", Positiontxt.Text)
cmd.Parameters.AddWithValue("estatus", StatusBox.Text)
cmd.Parameters.AddWithValue("efrontname", FrontNametxt.Text)
cmd.Parameters.AddWithValue("elastname", LastNametxt.Text)
cmd.Parameters.AddWithValue("edateregister", DateRegistertxt.Text)
cmd.Parameters.AddWithValue("enickname", NickNametxt.Text)
cmd.Parameters.AddWithValue("eidcard", IdCardtxt.Text)
cmd.Parameters.AddWithValue("ebirthday", Birthdaytxt.Text)
cmd.Parameters.AddWithValue("eprovinceborn", ProvinceBorntxt.Text)
cmd.Parameters.AddWithValue("eage", Agetxt.Text)
cmd.Parameters.AddWithValue("eheight", Heighttxt.Text)
cmd.Parameters.AddWithValue("eweight", Weighttxt.Text)
cmd.Parameters.AddWithValue("erace", Racetxt.Text)
cmd.Parameters.AddWithValue("enationality", Nationalitytxt.Text)
cmd.Parameters.AddWithValue("ereligion", Religiontxt.Text)
cmd.Parameters.AddWithValue("eaddress", Addresstxt.Text)
cmd.Parameters.AddWithValue("eroad", Roadtxt.Text)
cmd.Parameters.AddWithValue("edistrict", Districttxt.Text)
cmd.Parameters.AddWithValue("earea", Areatxt.Text)
cmd.Parameters.AddWithValue("eprovince", Provincetxt.Text)
cmd.Parameters.AddWithValue("epostalcode", PostalCodetxt.Text)
cmd.Parameters.AddWithValue("etelephone", Telephonetxt.Text)
cmd.Parameters.AddWithValue("emobile", Mobiletxt.Text)
cmd.Parameters.AddWithValue("eemail", Emailtxt.Text)
cmd.Parameters.AddWithValue("elocation", Locationbox.Text)
cmd.Parameters.AddWithValue("econdition", Conditionbox.Text)
cmd.Parameters.AddWithValue("emarry", Marrybox.Text)
cmd.Parameters.AddWithValue("efathername", FatherNametxt.Text)
cmd.Parameters.AddWithValue("efathersurname", FatherSurnametxt.Text)
cmd.Parameters.AddWithValue("efatherage", FatherAgetxt.Text)
cmd.Parameters.AddWithValue("efathercareer", FatherCareertxt.Text)
cmd.Parameters.AddWithValue("emothername", MotherNametxt.Text)
cmd.Parameters.AddWithValue("emothersurname", MotherSurnametxt.Text)
cmd.Parameters.AddWithValue("emotherage", MotherAgetxt.Text)
cmd.Parameters.AddWithValue("emothercareer", MotherCareertxt.Text)
cmd.Parameters.AddWithValue("erelativesnumber", RelativesNumbertxt.Text)
cmd.Parameters.AddWithValue("emanamount", ManAmounttxt.Text)
cmd.Parameters.AddWithValue("ewomanamount", WomanAmounttxt.Text)
cmd.Parameters.AddWithValue("enumber", Numbertxt.Text)
cmd.Parameters.AddWithValue("eonename", OneNametxt.Text)
cmd.Parameters.AddWithValue("eonesurname", OneSurNametxt.Text)
cmd.Parameters.AddWithValue("eoneage", OneAgetxt.Text)
cmd.Parameters.AddWithValue("eonecareer", OneCareertxt.Text)
cmd.Parameters.AddWithValue("etwoname", TwoNametxt.Text)
cmd.Parameters.AddWithValue("etwosurname", TwoSurnametxt.Text)
cmd.Parameters.AddWithValue("etwoage", TwoAgetxt.Text)
cmd.Parameters.AddWithValue("etwocareer", TwoCareertxt.Text)
cmd.Parameters.AddWithValue("ethreename", ThreeNametxt.Text)
cmd.Parameters.AddWithValue("ethreesurname", ThreeSurnametxt.Text)
cmd.Parameters.AddWithValue("ethreeage", ThreeAgetxt.Text)
cmd.Parameters.AddWithValue("ethreecareer", ThreeCareertxt.Text)
cmd.Parameters.AddWithValue("emarryname", MarryNametxt.Text)
cmd.Parameters.AddWithValue("emarrysurname", MarrySurnametxt.Text)
cmd.Parameters.AddWithValue("emarryage", MarryAgetxt.Text)
cmd.Parameters.AddWithValue("emarrycareer", MarryCareertxt.Text)
cmd.Parameters.AddWithValue("enumberchild", NumberChildtxt.Text)
cmd.Parameters.AddWithValue("esonamount", SonAmounttxt.Text)
cmd.Parameters.AddWithValue("edaughteramount", DaughterAmounttxt.Text)
cmd.Parameters.AddWithValue("eschool1", School1txt.Text)
cmd.Parameters.AddWithValue("ebranch1", Branch1txt.Text)
cmd.Parameters.AddWithValue("esince1", Since1txt.Text)
cmd.Parameters.AddWithValue("eto1", To1txt.Text)
cmd.Parameters.AddWithValue("eschool2", School2txt.Text)
cmd.Parameters.AddWithValue("ebranch2", Branch2txt.Text)
cmd.Parameters.AddWithValue("esince2", Since2txt.Text)
cmd.Parameters.AddWithValue("eto2", To2txt.Text)
cmd.Parameters.AddWithValue("eschool3", School3txt.Text)
cmd.Parameters.AddWithValue("ebranch3", Branch3txt.Text)
cmd.Parameters.AddWithValue("esince3", Since3txt.Text)
cmd.Parameters.AddWithValue("eto3", To3txt.Text)
cmd.Parameters.AddWithValue("eschool4", School4txt.Text)
cmd.Parameters.AddWithValue("ebranch4", Branch4txt.Text)
cmd.Parameters.AddWithValue("esince4", Since4txt.Text)
cmd.Parameters.AddWithValue("eto4", To4txt.Text)
cmd.Parameters.AddWithValue("eschool5", School5txt.Text)
cmd.Parameters.AddWithValue("ebranch5", Branch5txt.Text)
cmd.Parameters.AddWithValue("esince5", Since5txt.Text)
cmd.Parameters.AddWithValue("eto5", To5txt.Text)
cmd.Parameters.AddWithValue("eoffice1", Office1txt.Text)
cmd.Parameters.AddWithValue("eofficeaddress1", OfficeAddress1txt.Text)
cmd.Parameters.AddWithValue("ebegin1", Begin1txt.Text)
cmd.Parameters.AddWithValue("eend1", End1txt.Text)
cmd.Parameters.AddWithValue("esumtime1", SumTime1txt.Text)
cmd.Parameters.AddWithValue("eposition1", Position1txt.Text)
cmd.Parameters.AddWithValue("esalary1", Salary1txt.Text)
cmd.Parameters.AddWithValue("ereason1", Reason1txt.Text)
cmd.Parameters.AddWithValue("ejobquality1", JobQuality1txt.Text)
cmd.Parameters.AddWithValue("ecommandername1", CommanderName1txt.Text)
cmd.Parameters.AddWithValue("ephoneoffice1", PhoneOffice1txt.Text)
cmd.Parameters.AddWithValue("eoffice2", Office2txt.Text)
cmd.Parameters.AddWithValue("eofficeaddress2", OfficeAddress2txt.Text)
cmd.Parameters.AddWithValue("ebegin2", Begin2txt.Text)
cmd.Parameters.AddWithValue("eend2", End2txt.Text)
cmd.Parameters.AddWithValue("esumtime2", SumTime2txt.Text)
cmd.Parameters.AddWithValue("eposition2", Position2txt.Text)
cmd.Parameters.AddWithValue("esalary2", Salary2txt.Text)
cmd.Parameters.AddWithValue("ereason2", Reason2txt.Text)
cmd.Parameters.AddWithValue("ejobquality2", JobQuality2txt.Text)
cmd.Parameters.AddWithValue("ecommandername2", CommanderName2txt.Text)
cmd.Parameters.AddWithValue("ephoneoffice2", PhoneOffice2txt.Text)
cmd.Parameters.AddWithValue("eoffice3", Office3txt.Text)
cmd.Parameters.AddWithValue("eofficeaddress3", OfficeAddress3txt.Text)
cmd.Parameters.AddWithValue("ebegin3", Begin3txt.Text)
cmd.Parameters.AddWithValue("eend3", End3txt.Text)
cmd.Parameters.AddWithValue("esumtime3", SumTime3txt.Text)
cmd.Parameters.AddWithValue("eposition3", Position3txt.Text)
cmd.Parameters.AddWithValue("esalary3", Salary3txt.Text)
cmd.Parameters.AddWithValue("ereason3", Reason3txt.Text)
cmd.Parameters.AddWithValue("ejobquality3", JobQuality3txt.Text)
cmd.Parameters.AddWithValue("ecommandername3", CommanderName3txt.Text)
cmd.Parameters.AddWithValue("ephoneoffice3", PhoneOffice3txt.Text)
cmd.Parameters.AddWithValue("etrainningname1", TrainningName1txt.Text)
cmd.Parameters.AddWithValue("etrainbegin1", TrainBegin1txt.Text)
cmd.Parameters.AddWithValue("etrainend1", TrainEnd1txt.Text)
cmd.Parameters.AddWithValue("etrainposition1", TrainPosition1txt.Text)
cmd.Parameters.AddWithValue("etrainquality1", TrainQuality1txt.Text)
cmd.Parameters.AddWithValue("etrainningname2", TrainningName2txt.Text)
cmd.Parameters.AddWithValue("etrainbegin2", TrainBegin2txt.Text)
cmd.Parameters.AddWithValue("etrainend2", TrainEnd2txt.Text)
cmd.Parameters.AddWithValue("etrainposition2", TrainPosition2txt.Text)
cmd.Parameters.AddWithValue("etrainquality2", TrainQuality2txt.Text)
cmd.Parameters.AddWithValue("espeakthai", SpeakThaibox.Text)
cmd.Parameters.AddWithValue("ewritethai", WriteThaibox.Text)
cmd.Parameters.AddWithValue("ereadthai", ReadThaibox.Text)
cmd.Parameters.AddWithValue("espeakenglish", SpeakEnglishbox.Text)
cmd.Parameters.AddWithValue("ewriteenglish", WriteEnglishbox.Text)
cmd.Parameters.AddWithValue("ereadenglish", ReadEnglishbox.Text)
cmd.Parameters.AddWithValue("espeakjapan", SpeakJapanbox.Text)
cmd.Parameters.AddWithValue("ewritejapan", WriteJapanbox.Text)
cmd.Parameters.AddWithValue("ereadjapan", ReadJapanbox.Text)
cmd.Parameters.AddWithValue("espeakchina", SpeakChinabox.Text)
cmd.Parameters.AddWithValue("ewritechina", WriteChinabox.Text)
cmd.Parameters.AddWithValue("ereadchina", ReadChinabox.Text)
cmd.Parameters.AddWithValue("eprogram1", Program1txt.Text)
cmd.Parameters.AddWithValue("eclassbox1", Classbox1.Text)
cmd.Parameters.AddWithValue("eprogram2", Program2txt.Text)
cmd.Parameters.AddWithValue("eclassbox2", Classbox2.Text)
cmd.Parameters.AddWithValue("eprogram3", Program3txt.Text)
cmd.Parameters.AddWithValue("eclassbox3", Classbox3.Text)
cmd.Parameters.AddWithValue("etypewriterthai", TypeWriterThaitxt.Text)
cmd.Parameters.AddWithValue("etypewriterenglish", TypeWriterEnglishtxt.Text)
cmd.Parameters.AddWithValue("enodriver1", NoDriver1txt.Text)
cmd.Parameters.AddWithValue("ehavedriver1", HaveDriverbox1.Text)
cmd.Parameters.AddWithValue("enodriver2", NoDriver2txt.Text)
cmd.Parameters.AddWithValue("ehavedriver2", HaveDriverbox2.Text)
cmd.Parameters.AddWithValue("esport1", Sport1txt.Text)
cmd.Parameters.AddWithValue("esport2", Sport2txt.Text)
cmd.Parameters.AddWithValue("esport3", Sport3txt.Text)
cmd.Parameters.AddWithValue("ehobby1", Hobby1txt.Text)
cmd.Parameters.AddWithValue("ehobby2", Hobby2txt.Text)
cmd.Parameters.AddWithValue("ehobby3", Hobby3txt.Text)
cmd.Parameters.AddWithValue("etalent", Talenttxt.Text)
cmd.Parameters.AddWithValue("eyesno1", YesNo1box.Text)
cmd.Parameters.AddWithValue("ereasonprovince", ReasonProvincetxt.Text)
cmd.Parameters.AddWithValue("eoutsidername1", OutsiderName1txt.Text)
cmd.Parameters.AddWithValue("eoutsidersurname1", OutsiderSurname1txt.Text)
cmd.Parameters.AddWithValue("eoutsidercareer1", OutsiderCareer1txt.Text)
cmd.Parameters.AddWithValue("erelation1", Relation1txt.Text)
cmd.Parameters.AddWithValue("eoutsideraddress1", OutsiderAddress1txt.Text)
cmd.Parameters.AddWithValue("eoutsiderphone1", OutsiderPhone1txt.Text)
cmd.Parameters.AddWithValue("eoutsidername2", OutsiderName2txt.Text)
cmd.Parameters.AddWithValue("eoutsidersurname2", OutsiderSurname2txt.Text)
cmd.Parameters.AddWithValue("eoutsidercareer2", OutsiderCareer2txt.Text)
cmd.Parameters.AddWithValue("erelation2", Relation2txt.Text)
cmd.Parameters.AddWithValue("eoutsideraddress2", OutsiderAddress2txt.Text)
cmd.Parameters.AddWithValue("eoutsiderphone2", OutsiderPhone2txt.Text)
cmd.Parameters.AddWithValue("equarantername", QuaranterNametxt.Text)
cmd.Parameters.AddWithValue("equarantersurname", QuaranterSurNametxt.Text)
cmd.Parameters.AddWithValue("equarantercareer", QuaranterCareertxt.Text)
cmd.Parameters.AddWithValue("erelation3", Relation3txt.Text)
cmd.Parameters.AddWithValue("equaranteraddress", QuaranterAddresstxt.Text)
cmd.Parameters.AddWithValue("equaranterphone", QuaranterPhonetxt.Text)
cmd.Parameters.AddWithValue("equaranteroffice", QuaranterOfficetxt.Text)
cmd.Parameters.AddWithValue("equaranterposition", QuaranterPositiontxt.Text)
cmd.Parameters.AddWithValue("equaranterofficeaddress", QuaranterOfficeAddresstxt.Text)
cmd.Parameters.AddWithValue("equaranterofficeaddressphone", QuaranterOfficeAddressPhonetxt.Text)
cmd.Parameters.AddWithValue("eyesno2", YesNo2box.Text)
cmd.Parameters.AddWithValue("eremark1", Remark1txt.Text)
cmd.Parameters.AddWithValue("einformation", Informationtxt.Text)
cmd.Parameters.AddWithValue("eyesno3", YesNo3box.Text)
cmd.Parameters.AddWithValue("eremark2", Remark2txt.Text)
cmd.Parameters.AddWithValue("eyesno4", YesNo4box.Text)
cmd.Parameters.AddWithValue("erelativename", RelativeNametxt.Text)
cmd.Parameters.AddWithValue("erelativesurname", RelativeSurnametxt.Text)
cmd.Parameters.AddWithValue("erelativeposition", RelativePositiontxt.Text)
cmd.Parameters.AddWithValue("erelation4", Relation4txt.Text)
cmd.Parameters.AddWithValue("eyesno5", YesNo5box.Text)
cmd.Parameters.AddWithValue("eremark4", Remark3txt.Text)
cmd.Parameters.AddWithValue("eintroduce", Introducetxt.Text)
cmd.Parameters.AddWithValue("esalary", Salarytxt.Text)
cmd.Parameters.AddWithValue("etimesince", TimeSincebox.Text)
cmd.Parameters.AddWithValue("etimeto", TimeTobox.Text)
cmd.Parameters.AddWithValue("ebank", Bankbox.Text)
cmd.Parameters.AddWithValue("enoaccount", NoAccounttxt.Text)
cmd.Parameters.AddWithValue("epoint1", Point1txt.Text)
cmd.Parameters.AddWithValue("epoint2", Point2txt.Text)
cmd.Parameters.AddWithValue("epoint3", Point3txt.Text)
cmd.Parameters.AddWithValue("epoint4", Point4txt.Text)
cmd.Parameters.AddWithValue("epoint5", Point5txt.Text)
cmd.Parameters.AddWithValue("epoint6", Point6txt.Text)
cmd.Parameters.AddWithValue("epoint7", Point7txt.Text)
cmd.Parameters.AddWithValue("eaddexam", AddExamtxt.Text)
cmd.Parameters.AddWithValue("etimesloan", TimesLoantxt.Text)
cmd.Parameters.AddWithValue("esumloan", SumLoantxt.Text)
cmd.Parameters.AddWithValue("eloan", Loantxt.Text)
cmd.Parameters.AddWithValue("etimeswarn", TimesWarntxt.Text)
cmd.Parameters.AddWithValue("etimesfine", TimesFinetxt.Text)
cmd.Parameters.AddWithValue("esumfine", SumFinetxt.Text)
cmd.Parameters.AddWithValue("emistake1", Mistake1txt.Text)
cmd.Parameters.AddWithValue("emistake2", Mistake2txt.Text)
cmd.Parameters.AddWithValue("emistake3", Mistake3txt.Text)
cmd.Parameters.AddWithValue("echeckOut", OutOfficebox.Text)
cmd.Parameters.AddWithValue("ereasonout", ReasonOuttxt.Text)
cmd.Parameters.AddWithValue("NumberColumn", DBNull.Value)
Dim affect As Integer = cmd.ExecuteNonQuery()
If (affect < 1) Then
MsgBox("เกิดข้อผิดพลาด" & vbNewLine & "ไม่สามารถเพิ่มข้อมูลได้")
Else
MsgBox("เพิ่มข้อมูลเรียบร้อยแล้ว")
End If
'ClearBindings()
'EmpInfo()
'If (namebox.Items.Count > 0) Then
' namebox.SelectedIndex = 0
'End If
End If
End Sub
อุตส่าขยัน^^
Date :
2011-04-05 08:24:46
By :
mayapopy
ลองดูแล้วมันขึ้นแล้วนี่น่ะค่ะ
Date :
2011-04-05 09:08:15
By :
mayapopy
ทำไงดี เดี๋ยวเราไปเปลี่ยนฐานข้อมูลเป็น text ให้หมดดีไหม
ถ้าเปลี่ยนเป็น text ก็ต้องมี โค้ดที่ใช้ตรวจสอบค่า ว่าให้คีย์ได้เฉพาะตัวเลข
ขอตัวอย่างโค้ดหน่อยค่ะ
ถ้าทำไม่ได้ จะได้ไปนั่งไล่เปลี่ยน แหะๆ เหนื่อยเลย
Date :
2011-04-05 09:21:21
By :
mayapopy
ต้องเป็นแบบนี้มั้ง
Code (VB.NET)
cmd.Parameters.Add("@EmpPostalCode", OleDbType.Integer, IIf(EmpPostalCodetxt.Text<>"",Int32.Parse(EmpPostalCodetxt.Text),DBNull.Value))
ว่าแต่ ลองเอา SaveData ที่ให้ไว้ไปใช้รึยัง (เป็นโค้ดสำหรับเอาข้อมูลใน DataSet ไปบันทึกลงฐานข้อมูล)
แต่มันต้องปรับนิดหน่อยนะ
ตรง ConnectionString
กับ YourDataSetInstance
ลองใช้วิธี SaveData ดีกว่า
ไม่งั้นแก้โปรแกรมบานเลย
ประวัติการแก้ไข 2011-04-05 09:25:40
Date :
2011-04-05 09:23:09
By :
watcharop
คือยังงง อยู่ว่าจะเอาไปใช้ตรงไหนน่ะค่ะ
ใช้ใน addbtt ปุ่มบันทึกข้อมูลใช่ไหม เอาไปแทน ข้อมูลในนั้นเลย
ยังงงอยู่ แหะๆ^^
Date :
2011-04-05 10:20:13
By :
mayapopy
คราวนี้ขึ้นแบบนี้
Date :
2011-04-05 10:29:34
By :
mayapopy
Code (VB.NET)
Public Sub SaveData()
If con.State <> ConnectionState.Open Then con.Open()
Dim da As New OleDbDataAdapter()
da.SelectCommand = New OleDbCommand("SELECT * FROM EmpProfile WHERE IDNumber=0", con)
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)
cb.ConflictOption = ConflictOption.OverwriteChanges
da.InsertCommand = cb.GetInsertCommand(True)
da.InsertCommand.Connection = con
da.UpdateCommand = cb.GetUpdateCommand(True)
da.UpdateCommand.Connection = con
da.DeleteCommand = cb.GetDeleteCommand(True)
da.DeleteCommand.Connection = con
da.Update(data, "EmpProfile")
End Sub
Private Sub Addbtt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Addbtt.Click
Try
Me.SaveData()
Catch ex As Exception
Messagebox.Show(ex.Message)
Finally
con.Close
End Try
End Sub
ประวัติการแก้ไข 2011-04-05 11:02:18
Date :
2011-04-05 11:01:40
By :
watcharop
ลองแล้ว มันเป็นแบบนี้ค่ะ
ใช้โค้ด savedata() ความคิดเห็นที่ 25 ใช่ไหมคะ
หรือว่าเรายังต้องกรอกข้อมูลให้ครบอยู่....
Date :
2011-04-05 11:15:01
By :
mayapopy
ลองกรอกข้อมูลครบแล้วมันก็ขึ้นแบบนี้เหมือนกัน
ไม่ทราบว่าเราต้องใช้อีกอันนึงหรือเปล่าคะ งง
ใช้อันล่าสุดไว้ก่อน(ความคิดเห็นที่ 25) อิอิ^^
Date :
2011-04-05 11:20:57
By :
mayapopy
คุณหางอึ่งคะ ? จะขอความกรุณาขอโค้ดตัวอย่าง ตรวจสอบค่า หน่อยนะคะ
ตัวอย่าง(เป็นคำพูดนะ) ถ้า textbox1 ไม่ใช่ "ตัวเลข" ให้ขึ้น error แล้วก็ return
หรือ textbox1 ต้องเป็นตัวเลขเท่านั้น
แล้วก็ เอา วันที่ด้วยค่ะ (textbox1 ต้องเป็นวันที่เท่านั้น)
อ๋อ ลืม ต้องกำหนดด้วยน่ะค่ะ ว่าในช่องนั้น ห้ามมีตัวอักษร (เผื่อใส่ผสมกันได้ .... จะให้มันใส่ผสมไม่ได้)
ว่าจะลองไปแก้ database ให้เป็น text แล้วน่ะค่ะ ติดปัญหา number เป็นค่าว่าง แก้ไม่ได้ งั้นต้องไปแก้ที่ต้นเหตุแระ
ใจร้อน อยากให้โปรแกรมเสร็จเร็วๆ ^^
ขอบคุณ ล่วงหน้าค่ะ
เท่าที่ลองคิดดูน่าจะเป็นแบบนี้หรือเปล่า
dim a as interger
if textbox1.text <> a then
msgbox("textbox1 ต้องใส่เป็นตัวเลขเท่านั้น")
end if
ประมาณคร่าวๆนะ
แต่วันที่นี่สิ ไม่รู้ทำไง
ถามเองตอบเอง แหะๆ บ้าไปแล้ว
Date :
2011-04-05 11:27:33
By :
mayapopy
แล้วอย่าลืมแก้โค้ดใน SaveData ด้วยล่ะ
ตรง StringConnection กับ YourDataSetInstance
มันต้องแก้เป็นอะไรหรอคะ งงเจ้าค่ะ
Date :
2011-04-05 11:40:54
By :
mayapopy
Load balance : Server 00