| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 504 人关注过本帖
标题:一段VB的增加到SQL的程序怎么改
只看楼主 加入收藏
huchenggong
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-12
收藏
 问题点数:0 回复次数:4 
一段VB的增加到SQL的程序怎么改

该段程序是将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

搜索更多相关主题的帖子: SQL TEXTBOX 数据库 
2006-04-22 18:14
huchenggong
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-12
收藏
得分:0 

难到没有人会吗 ? 呵呵 不可能的吧 ~~~ 这么多人

2006-04-23 15:44
jackboy
Rank: 2
等 级:论坛游民
帖 子:163
专家分:27
注 册:2005-10-9
收藏
得分:0 

你把程序发上来,这么长一段代码在看太累了


2006-04-23 16:47
xxxisme
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-3-15
收藏
得分:0 

就是啊~~~插入方法不需要这么长的啊

2006-04-23 21:48
gandaihua
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-4-24
收藏
得分:0 
用得着写得这么长吗,看都看不懂呀
2006-04-24 09:00
快速回复:一段VB的增加到SQL的程序怎么改
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.060134 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved