| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 407 人关注过本帖
标题:大家都来帮忙 看看
只看楼主 加入收藏
wm_198628
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-10-30
结帖率:100%
收藏
 问题点数:0 回复次数:2 
大家都来帮忙 看看

这是VB连接SQL数据库的添加操作
我调试了很多次了 但是总是提示"在此上下文中不允许列名,只允许出现常量,变量或表达式
Private Sub Command1_Click()
Dim add As Booleanadd = TrueIf Trim(txtbh.Text) = "" Then
MsgBox "请输入编号", vbExclamation, "验证"
txtbh.SetFocus
Exit Sub
End If
If Trim(txtxsxm.Text) = "" Then
MsgBox "请输入姓名", vbExclamation, "验证"
txtxsxm.SetFocus
Exit Sub
End If
If Trim(txtxb.Text) = "" Then
MsgBox "请输入性别", vbExclamation, "验证"
txtxb.SetFocus
Exit Sub
End If
If Trim(txtcsrq.Text) = "" Then
MsgBox "请输入出生年月", vbExclamation, "验证"
txtcsrq.SetFocus
Exit Sub
End If
If Trim(txtjg.Text) = "" Then
MsgBox "请输入籍贯", vbExclamation, "验证"
txtjg.SetFocus
Exit Sub
End If
If Trim(txtmz.Text) = "" Then
MsgBox "请输入民族", vbExclamation, "验证"
txtmz.SetFocus
Exit Sub
End If
If Trim(txtsfzh.Text) = "" Then
MsgBox "请输入身份证号", vbExclamation, "验证"
txtsfzh.SetFocus
Exit Sub
End If
If Trim(txtzw.Text) = "" Then
MsgBox "请输入职务", vbExclamation, "验证"
txtzw.SetFocus
Exit Sub
End If
If Trim(txtjzdz.Text) = "" Then
MsgBox "请输入居住地址", vbExclamation, "验证"
txtjzdz.SetFocus
Exit Sub
End If
If Trim(txtxszh.Text) = "" Then
MsgBox "请输入学生证号", vbExclamation, "验证"
txtxszh.SetFocus
Exit Sub
End If
If Trim(txtyzbm.Text) = "" Then
MsgBox "请输入邮政编码", vbExclamation, "验证"
txtyzbm.SetFocus
Exit Sub
End If
If Trim(txtdh.Text) = "" Then
MsgBox "请输入联系电话", vbExclamation, "验证"
txtdh.SetFocus
Exit Sub
End If
If Trim(txtbz.Text) = "" Then
MsgBox "请输入备注", vbExclamation, "验证"
txtbz.SetFocus
Exit Sub
End If

If add Then
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=student"
conn.Open
Set rs = conn.Execute("select * from 学生基本信息表 where student_id=" & txtbh.Text)
If Not rs.EOF Then
MsgBox ("此记录重复,请重新输入!")
Exit Sub
Else
conn.Execute ("insert into 学生基本信息表(student_id,student_xm,student_xb,student_sr,student_jg,student_mz,student_sfzh,student_zw,student_jzdz,student_xszh,student_yzbm,student_dh,student_bz) values(" & txtbh.Text & ",'" & txtxsxm.Text & "','" & txtxb.Text & "','" & txtcsrq.Text & "','" & txtjg.Text & "'," & txtmz.Text & "," & txtsfzh.Text & "," & txtzw.Text & "," & txtjzdz.Text & "," & txtxszh.Text & "," & txtyzbm.Text & "," & txtdh.Text & ",'" & txtbz.Text & "')")
MsgBox "数据添加成功!", vbInformation, "ADD"
End If
End If
End Sub
先在这里谢谢大家了,希望能帮忙解决这个问题!!!

搜索更多相关主题的帖子: 姓名 SQL数据库 上下文 表达式 
2007-01-10 10:04
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
得分:0 
哪句话出题了?

是那个SQL语句吗?能不能贴出来最后要执行SQL语句

天津网站建设 http://www./
2007-01-10 12:29
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
是他的Insert Into错..

我的msn: myfend@
2007-01-10 12:37
快速回复:大家都来帮忙 看看
数据加载中...
 
   



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

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