vb 做数据库系统实时语法错误

来源:百度知道 编辑:UC知道 时间:2024/05/24 04:47:43
添加:
Private Sub Command7_Click()
Dim insertconn As ADODB.Connection
Set insertconn = New ADODB.Connection

insertconn.ConnectionString = "这里长省了"

insertstr = "insert into 学生表(学号,姓名,性别,年龄,系别)values(" + Text1.Text + ",'" + Text2.Text + "','" + Text3.Text + "'," + Text4.Text + ",'" + Text5.Text + "')"

insertconn.Open
insertconn.Execute (insertstr)
insertconn.Close
MsgBox "保存成功!" + vbInformation + vbOKOnly

更新:
Dim upconn As ADODB.Connection
Set upconn = New ADODB.Connection
upconn.ConnectionString = "这里长省了"

upstr = "update 学生表 set 年龄=" + Text4.Text + "where 学号='" + Text1.Text + "'"

upconn.Open
upconn.Execute (upstr)
upconn.Close
MsgBox "更新成功!" + vbInformation + vbOKOnly

删除:
Dim delconn As ADOD

你的学号等如果是数值型的话应该在 Text6.Text 两边加#而不是加'
每个代表值的变量左右都要加'
如:
insertstr = "insert into 学生表(学号,姓名,性别,年龄,系别)values('" + Text1.Text + "','" + Text2.Text + "','" + Text3.Text + "','" + Text4.Text + "','" + Text5.Text + "')"
我看你的只有部分加了,比较乱
我给你发段代码你举一反三吧.
Private Sub Cmd_Find_Click() '【查询】按钮
If Option1.Value = True Then '按学生姓名查询
If Combo1.Text = "" Then
Call MyMsg '调用自定义函数,用于信息提示
Else
Adodc1.RecordSource = "select * from tb_stu where 学生姓名='" + Combo1.Text + "'"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End If
ElseIf Option2.Value = True Then '按学生性别查询
If Combo2.Text = "" Then
Call MyMsg '调用自定义函数,用于信息提示
Else
Adodc1.RecordSource = "select * from tb_stu where 性别=&