#22003输出的范围值为列'专栏名称'在第1行

时间:2014-12-01 04:48:28

标签: mysql database vb.net

我将此代码保存在数据库中

mycom.Connection = cn
 mycom.CommandText = "Insert into 
tbl_employee(LastName,FirstName,MiddleName,NickName,DHired,Position,Gender,Address,
    Cellphone,FName,FOccupation,MName,MOccupation,DSpoken,BDate,Place,CStatus,Citizenship,
    Height,Weight,Religion,EName,EContact,SSS,Pagibig,Philhealth,TIN,Spouse,SOccupation,
    ChildNo,C1,A1,C2,A2,Motto,FMovie,FQuotation,FActress,FColor,Moment,FActor,PastTime,FDay,
    ESchool,EYG,SSchool,SYG,CSchool,CYG,CCourse,CUG,VSchool,VYG,VCourse,MSchool,MYG,MDegree,
    SSkills,STitle1,SAddress1,SDate1,STitle2,SAddress2,SDate2,STitle3,SAddress3,SDate3,
    STitle4,SAddress4,SDate4,STitle5,SAddress5,SDate5) values ('" & txtLastName.Text & "','" 
    & txtFirstName.Text & "','" & txtMiddleName.Text & "','" & txtNickname.Text & "','" & dtpDate.Text & "','" & cboPosition.Text & "','" & cboGender.Text & "','" & txtAddress.Text
     & "','" & txtCellphone.Text & "','" & txtFName.Text & "','" & txtFOccupation.Text & "','"
     & txtMName.Text & "','" & txtMOccupation.Text & "','" & txtDialects.Text & "','" & 
    dtpBdate.Text & "','" & txtPlace.Text & "','" & cboCStatus.Text & "','" & 
    txtCitizenship.Text & "','" & txtHeight.Text & "','" & txtWeight.Text & "','" & 
    txtReligion.Text & "','" & txtEName.Text & "','" & txtEPhone.Text & "','" & txtSSS.Text &
     "','" & txtPagibig.Text & "','" & txtPhilhealth.Text & "','" & txtTin.Text & "','" &
     txtSpouse.Text & "','" & txtSOccupation.Text & "','" & txtChildNo.Text & "','" &
     txtChild1.Text & "','" & txtAge1.Text & "','" & txtChild2.Text & "','" & txtAge2.Text & 
    "','" & txtMotto.Text & "','" & txtMovie.Text & "','" & txtQuotation.Text & "','" & txtActress.Text & "','" & txtColor.Text & "','" & txtMoment.Text & "','" & txtActor.Text & "','" & txtPasttime.Text & "','" & txtDay.Text & "','" & txtElemSchool.Text & "','" &
     txtElemYG.Text & "','" & txtHSSchool.Text & "','" & txtHSYG.Text & "','" & 
    txtCollSchool.Text & "','" & txtCollYG.Text & "','" & txtCollDegree.Text & "','" & 
    txtYearLevel.Text & "','" & txtVocSchool.Text & "','" & txtVocYG.Text & "','" & 
    txtVocCourse.Text & "','" & txtEMasSchool.Text & "','" & txtEMasYG.Text & "','" &
     txtEMasDegree.Text & "','" & txtSSkills.Text & "','" & txtSTTitle1.Text & "','" &
     txtSTLoc1.Text & "','" & txtSTDate1.Text & "','" & txtSTTitle2.Text & "','" & 
    txtSTLoc2.Text & "','" & txtSTDate2.Text & "','" & txtSTTitle3.Text & "','" &
     txtSTLoc3.Text & "','" & txtSTDate3.Text & "','" & txtSTTitle4.Text & "','" &
     txtSTLoc4.Text & "','" & txtSTDate4.Text & "','" & txtSTTitle5.Text & "','" &
     txtSTLoc5.Text & "','" & txtSTDate5.Text & "');"

            myr = mycom.ExecuteReader

始终显示此错误

#22003Out of range value adjusted for column 'A1' at row 1

任何人都可以帮我这个吗

2 个答案:

答案 0 :(得分:0)

假设A1提供了列txtAge1.Text

  • 错误可能是A1错误类型,例如int并输入abctxtAge1.Text会返回string还是int

  • 或类型太小,例如byte并输入300


防止SQL注入

根据MySQL documentation

的基本模式
   cmd.CommandText = "INSERT INTO myTable VALUES(NULL, @number)"
   cmd.Prepare()
   cmd.Parameters.AddWithValue("@number", 1)
   cmd.ExecuteNonQuery()

答案 1 :(得分:0)

更改datatype age并将查询更改为参数化查询,如下所示

 MySqlCommand m = new MySqlCommand(readCommand);
 m.Parameters.Add(new MySqlParameter("LastName", txtLastName.Text));
 m.Parameters.Add(new MySqlParameter("FirstName", txtFirstName.Text));
 MySqlDataReader r = m.ExecuteReader();