Private Sub Form_Load()
 '建立数据源的连接
 Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=usermanage.mdb;Persist Security Info=False"
 '查询所有记录,并按"部门编号"排序
 Adodc1.RecordSource = "select * from 用户信息表 order by 操作员编号"
 Adodc1.Refresh
 For i = 0 To 4
  Text1(i).Enabled = False
 Next i
 CmdSave.Enabled = False
End Sub
Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
 Select Case Index
  Case Is = Index
    If KeyCode = vbKeyReturn And Index < 4 Then Text1(Index + 1).SetFocus '回车获得焦点
    If KeyCode = vbKeyReturn And Index = 4 Then CmdSave.SetFocus
    If KeyCode = vbKeyUp And Index > 1 Then Text1(Index - 1).SetFocus
 End Select
End Sub
Private Sub CmdAdd_Click()     '添加记录
 Adodc1.Recordset.AddNew
 For i = 0 To 4
   Text1(i).Enabled = True
   Text1(i).Text = ""
 Next i
 Text1(0).SetFocus
 CmdAdd.Enabled = False
 CmdDelete.Enabled = False
 CmdModify.Enabled = False
 CmdSave.Enabled = True
End Sub
Private Sub CmdModify_Click()     '修改记录
 If Adodc1.Recordset.RecordCount <> 0 Then
   For i = 0 To 4
     Text1(i).Enabled = True
   Next i
   CmdSave.Enabled = True
   CmdAdd.Enabled = False
   CmdModify.Enabled = False
   CmdDelete.Enabled = False
 Else
   MsgBox ("没有要修改的数据!")
 End If
End Sub
Private Sub CmdDelete_Click()     '删除记录
 Dim myval As String
 myval = MsgBox("是否要删除该记录?", vbYesNo)
 If myval = vbYes Then
  Adodc1.Recordset.Delete
  Adodc1.Recordset.MoveNext
  If Adodc1.Recordset.EOF = True Then Adodc1.Recordset.MoveLast
    For i = 0 To 4
        Text1(i).Enabled = False
    Next i
 End If
End Sub
Private Sub CmdSave_Click()
 If Text1(0).Text = "" Then
   MsgBox "操作员编号不允许为空!"
   Exit Sub
 End If
 If Text1(1).Text = "" Then
   MsgBox "姓名不允许为空!"
   Exit Sub
 End If
 If Text1(2).Text = "" Then
   MsgBox "用户ID号不允许为空!"
   Exit Sub
 End If
 If Text1(3).Text = "" Then
   MsgBox "密码不允许为空!"
   Exit Sub
 End If
 If Text1(4).Text = "" Then
   MsgBox "所属部门不允许为空!"
   Exit Sub
 End If
 Adodc1.Recordset.Update     '更新记录
 '设置控件不可用
 For i = 0 To 4
     Text1(i).Enabled = False
 Next i
 CmdSave.Enabled = False
 CmdAdd.Enabled = True
 CmdModify.Enabled = True
 CmdDelete.Enabled = True
End Sub
Private Sub CmdExit_Click()
  Unload Me
End Sub

解决方案 »

  1.   

    只要改一下这个就行了
    Adodc1.ConnectionString = "Provider=sqloledb;server=ip地址;Initial  Catalog=数据库名;user  id=用户名;password=密码"
      

  2.   

    http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=183662
      

  3.   

    Adodc1.ConnectionString ="driver=SQL Server;server=计算机名或IP地址;uid=sa;pwd=;database=数据库名"
      

  4.   

    adodc有个向导可以生成连接语句的啊。什么类型的数据库都可以。
      

  5.   

    把连接语句改成连sql的就行了
      

  6.   

    adodc控件=>右键=>adodc属性=>连接字符串=>生成=>SQLserver=>下一步=>自己看看咯
      

  7.   

    首先你得建立一个SQLserver数据库,比如名叫customers,然后将access里的数据和表复制到SQLserver数据库中。
    然后你才能用下面的连接语句。()号内的为说明内容。
    Adodc1.ConnectionString ="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa(用户名);pwd=密码(没有的话就将pwd=...;这段去掉);Initial Catalog=customers(数据库的名字);Data Source=SERVER(SQLServer服务器的计算机名或者IP)"
      

  8.   

    现在 可以通过,很感谢楼上的各位大哥的指点。。
    但是还有一个小问题。就是在编译下面这段程序报错“在关键字”select“附近有语法错误。点调试后光标出现在Adodc1.Refresh上面。注释这条语句后,就可以编译通过。不知道是何原因?Private Sub Form_Load()
     '建立数据源的连接
     Adodc1.ConnectionString = "driver=SQL Server;server=front;uid=sa;pwd=;database=usermanage" '查询所有记录,并按"部门编号"排序
     Adodc1.RecordSource = "select * from 用户信息表 order by 操作员编号"
     Adodc1.Refresh
     For i = 0 To 4
      Text1(i).Enabled = False
     Next i
     CmdSave.Enabled = False
    End Sub
      

  9.   

    strCon = "Provider=SQLOLEDB.1;Password=;Persist Security Info=True;User ID=sa;Initial Catalog=usermanage;Data Source=frontDim Conn As New ADODB.Connection
    Dim ss
    dbCon.Open strCon
    Set ss=Conn.Execute("select * from 用户信息表 order by 操作员编号")
    Do While Not ss.EOF
         theRe = theRe & ss(0)
         ss.MoveNext
    Loop
    Set ss = Nothing
    这样就可以了啊,ss(0)为第一个字段,另外建议不要用*号,改成你要读取的字段名
      

  10.   

    sql里面的表和你原来的表一样吗?你在查询分析器运行可以通过吗?
      

  11.   

    Select Case Index
      Case Is = Index
        If KeyCode = vbKeyReturn And Index < 4 Then Text1(Index + 1).SetFocus '回车获得焦点
        If KeyCode = vbKeyReturn And Index = 4 Then CmdSave.SetFocus
        If KeyCode = vbKeyUp And Index > 1 Then Text1(Index - 1).SetFocus
     End Select
     如果index = 3,且按下回车,你说他应该执行那条语句?
       第一个和第3个if都执行了哦!!!
      

  12.   

    更正,楼上没有看清楚,呵呵!!
       keycode已经改变
      

  13.   

    执行“select * from 用户信息表 order by 操作员编号”不行是吗?
    你的sql里的usermanage有“用户信息表吗”?怎么个无效啊?