| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 650 人关注过本帖, 1 人收藏
标题:添加数据的代码写好了,可是修改记录的代码怎么写都显示错误。
取消只看楼主 加入收藏
sankes
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2009-7-19
结帖率:100%
收藏(1)
已结贴  问题点数:10 回复次数:1 
添加数据的代码写好了,可是修改记录的代码怎么写都显示错误。
下面是添加记录的代码。请教修改记录的代码。
Private Sub cmdAdd_Click()
    Dim sc As Integer

        If Not (Testtxt(txtNo.Text) Or Testtxt(txtName.Text) Or Testtxt(txtSex.Text) Or Testtxt(txtBookTime.Text) Or Testtxt(txtTel.Text) Or Testtxt(txtEnrolTime.Text)) Then
            MsgBox "带 * 号为必填项", vbOKOnly + vbExclamation, "警告"
            txtNo.SetFocus
        Exit Sub
        End If
            sc = MsgBox("确实要添加这条记录吗?", vbOKCancel, "提示信息")
        If sc = 1 Then
            Dim conn As New ADODB.Connection
            Dim rs As New ADODB.Recordset
            Dim Str1 As String
            Dim Str2 As String
            Dim Str3 As String
                Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
                Str2 = "Data Source=C:\Users\sAnKes\Desktop\大学生心理健康中心\data.mdb;"
                Str3 = "Jet OLEDB:Database Password="
                conn.Open Str1 & Str2 & Str3
                strSQL = "select * from 预约者"
                rs.Open strSQL, conn, 3, 3
                rs.AddNew
                rs!编号 = txtNo.Text
                rs!姓名 = txtName.Text
                rs!性别 = txtSex.Text
                rs!所在学院 = txtCollege.Text
                rs!所在专业 = txtSpeciality.Text
                rs!联系电话 = txtTel.Text
                rs!预约时间 = txtBookTime.Text
                rs!登记时间 = txtEnrolTime.Text
                rs!备注 = txtRemark.Text
                rs.Update
                rs.Close
                conn.Close
                MsgBox ("添加记录成功!")
                Adodc1.Refresh
        End If
            txtNo.Text = ""
            txtName.Text = ""
            txtSex.Text = ""
            txtCollege.Text = ""
            txtSpeciality.Text = ""
            txtTel.Text = ""
            txtBookTime.Text = ""
            txtEnrolTime.Text = ""
            txtRemark.Text = ""
   
End Sub

Private Sub cmdEdit_Click()
Dim sc As Integer
    Frame2.Visible = True
    Frame1.Visible = False
    cmdAdd.Enabled = False
    cmdDelect.Enabled = False
    cmdPrint.Enabled = False
    cmdPutout.Enabled = False
    cmdEdit.Caption = "保存"
   
    txtNo.Text = Text2(0)
    txtName.Text = Text2(1)
    txtSex.Text = Text2(2)
    txtCollege.Text = Text2(3)
    txtSpeciality.Text = Text2(4)
    txtTel.Text = Text2(5)
    txtBookTime.Text = Text2(6)
    txtEnrolTime.Text = Text2(7)
    txtRemark.Text = Text2(8)
   
        If Not (Testtxt(txtNo.Text) Or Testtxt(txtName.Text) Or Testtxt(txtSex.Text) Or Testtxt(txtBookTime.Text) Or Testtxt(txtTel.Text) Or Testtxt(txtEnrolTime.Text)) Then
            MsgBox "带 * 号为必填项", vbOKOnly + vbExclamation, "警告"
            txtNo.SetFocus
        Exit Sub
        End If

            Dim conn As New ADODB.Connection
            Dim rs As New ADODB.Recordset
            Dim Str1 As String
            Dim Str2 As String
            Dim Str3 As String
                Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
                Str2 = "Data Source=C:\Users\sAnKes\Desktop\大学生心理健康中心\data.mdb;"
                Str3 = "Jet OLEDB:Database Password="
                conn.Open Str1 & Str2 & Str3
                strSQL = "select * from 预约者"
                rs.Open strSQL, conn, 1, 3
                rs!编号 = 1
                rs!姓名 = txtName.Text
                rs!性别 = txtSex.Text
                rs!所在学院 = txtCollege.Text
                rs!所在专业 = txtSpeciality.Text
                rs!联系电话 = txtTel.Text
                rs!预约时间 = 2004 - 2 - 2
                rs!登记时间 = 2004 - 2 - 2
                rs!备注 = txtRemark.Text
                rs.Update
                rs.Close
                conn.Close
                Adodc1.Refresh

End Sub
搜索更多相关主题的帖子: 修改数据 
2009-08-20 12:37
sankes
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2009-7-19
收藏
得分:0 
直接用update语句?能大概举个例子吗?
2009-08-20 15:09
快速回复:添加数据的代码写好了,可是修改记录的代码怎么写都显示错误。
数据加载中...
 
   



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

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