该段程序是将VB中 一些TEXTBOX中的值 插入到 SQLSERVER2000 的数据库表中的一段程序<增加按钮>
可是当我在VB界面中的其中任何一个TEXTBOX中输入值后, 当离开TEXTBOX后该TEXTBOX值不见了成了空的 刚刚输入的值不见了 我设置过断点 在 下面<1>语句 运行时填如的值在此是空的 最后我插入在student 和 STUDENT_INFO中的值为两个空的记录 请问各位高手该怎么改~~ 在此先谢谢~~~
Private Sub cmdAdd_Click()
Dim cmd As Command
Set cmd = New Command
'表STUDENT中的数据
Dim S_NOval As String
Dim SEX_NAMEval As String
Dim GRADE_NAMEval As String
Dim YEARS_NAMEval As String
Dim S_NAMEval As String
Dim UNIT_NAMEval As String
Dim ID_NOval As String
Dim Addressval As String
Dim PostCodeval As String
Dim Max_centval As String
Dim CULTURE_NAMEval As String
Dim SPECIALTY_NAMEval As String
'表STUDENT_INFO中的数据
Dim BIRTHDAYval As String
Dim AREAS_NAMEval As String
Dim POLITICS_NAMEval As String
Dim POL_DAYval As String
Dim RACE_NAMEval As String
Dim NATIVEval As String
Dim GAT_NAMEval As String
Dim HEALTH_NAMEval As String
Dim RELIGION_NAMEval As String
Dim EMAILval As String
Dim REMARKval As String
'表STUDENT中的数据 赋值
<1> S_NOval = txtS_NO.Text
SEX_NAMEval = txtSEX_NAME.Text
GRADE_NAMEval = txtGRADE_NAME.Text
YEARS_NAMEval = txtYEARS_NAME.Text
S_NAMEval = txtS_NAME.Text
UNIT_NAMEval = txtUNIT_NAME.Text
ID_NOval = txtID_NO.Text
Addressval = txtAddress.Text
PostCodeval = txtPostCode.Text
Max_centval = txtMax_cent.Text
CULTURE_NAMEval = txtCULTURE_NAME.Text
SPECIALTY_NAMEval = txtSPECIALTY_NAME.Text
'表STUDENT_INFO中的数据 赋值
BIRTHDAYval = txtBIRTHDAY.Text
AREAS_NAMEval = txtAREAS_NAME.Text
POLITICS_NAMEval = txtPOLITICS_NAME.Text
POL_DAYval = txtPOL_DAY.Text
RACE_NAMEval = txtRACE_NAME.Text
NATIVEval = txtNATIVE.Text
GAT_NAMEval = txtGAT_NAME.Text
HEALTH_NAMEval = txtHEALTH_NAME.Text
RELIGION_NAMEval = txtRELIGION_NAME.Text
EMAILval = EMAIL.Text
REMARKval = txtREMARK.Text
Dim err As ADODB.Error
'插入学生基本信息的sql语句 表中要求不为空的字段用 insert插入,其他字段用update更新<因为是直接COPY 过来的这段程序下面可能有一点错位 我相信你能看的懂 的>
With cmd
.ActiveConnection = cn
.CommandText = " insert into student(s_no,s_name,Address,PostCode,Max_cent,ID_NO) " & _
" values('" & S_NOval & " ' ,'" & S_NAMEval & "','" & Addressval & " ' , '" & PostCodeval & " ' ,'" & Max_centval & " ','" & ID_NOval & " ') " & _
" update student set sex_no=(select sex_no from sex where sex_name='" & SEX_NAMEval & " ') , " & _
" unit_no=(select unit_no from unit where unit_name='" & UNIT_NAMEval & " '), " & _
" grade_no=(select grade_no from grade where grade_name='" & GRADE_NAMEval & " ') , " & _
" years_no=(select years_no from years where years_name='" & YEARS_NAMEval & " ') , " & _
" culture_no=(select culture_no from culture where culture_name='" & CULTURE_NAMEval & " ') , " & _
" specialty_no=(select specialty_no from specialty where specialty_name='" & SPECIALTY_NAMEval & " ') " & _
" where s_no='" & S_NOval & " ' " & _
" insert into student_info(s_no,BIRTHDAY,POL_DAY,REMARK,EMAIL) " & _
" values( '" & S_NOval & " ' ,'" & BIRTHDAYval & " ' ,'" & POL_DAYval & " ' ,'" & REMARKval & " ' , '" & EMAILval & " ') " & _
" update student_info set areas_no=(select areas_no from areas where areas_name='" & AREAS_NAMEval & " ') , " & _
" politics_no=(select politics_no from politics where politics_name='" & POLITICS_NAMEval & " ') , " & _
" race_no=(select race_no from races where race_name='" & RACE_NAMEval & " ') , " & _
" native=(select areas_no from areas where areas_name='" & NATIVEval & " ') , " & _
" gat_no=(select gat_no from gat where gat_name='" & GAT_NAMEval & " ') , " & _
" health_no=(select health_no from health where health_name='" & HEALTH_NAMEval & " '), " & _
" religion_no=(select religion_no from religion where religion_name='" & RELIGION_NAMEval & " ') " & _
" where s_no='" & S_NOval & " '"
End With
On Error GoTo errorhandler
cmd.Execute
MsgBox "成功添加数据!"
errorhandler:
For Each err In cn.Errors
MsgBox "number:" & err.Number & vbCrLf & "source:" & err.Source & vbCrLf & "text:" & err.Description
Next
End Sub