急!VB操作Access问题!在线等!高分!
OptionExplicitDimrsAsADODB.RecordsetDimstrSQLAsStringDimmsgAsStringDimIndexAsIntegerD...
Option Explicit
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim msg As String
Dim Index As Integer
Dim flag As String '判断是新增记录还是修改记录
Private Sub Form_Load()
Call LoadData '装载数据
If rs.RecordCount > 0 Then
Call ShowData '显示数据
Else
For Index = 0 To 3
CmdMove(Index).Enabled = False
Next Index
End If
'控件可用性
CmdAdd.Enabled = True: CmdModify.Enabled = True: CmdDelete.Enabled = True
CmdCancel.Enabled = False: CmdSave.Enabled = False
End Sub
Private Sub ShowData()
'在文本框中显示数据
If rs.RecordCount <> 0 And rs.EOF = False Then
For Index = 8 To 28
If rs.Fields(Index) <> "" Then
txtItem(Index).Text = rs.Fields(Index)
Else
txtItem(Index).Text = ""
End If
txtItem(Index).Enabled = False
Next Index
End If
End Sub
Private Sub LoadData()
'装载数据
rs = "select * from Indicator order by Serial"
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
End Sub
。。。有DataEnv设计器,需将各TextBox中数据存入Indicator表,并能显示在DataGrid1控件中,数据库连接不会,在线等~解决后有高分相送!
消息还没收到~最好不用ADO,其他模块也没用。 展开
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim msg As String
Dim Index As Integer
Dim flag As String '判断是新增记录还是修改记录
Private Sub Form_Load()
Call LoadData '装载数据
If rs.RecordCount > 0 Then
Call ShowData '显示数据
Else
For Index = 0 To 3
CmdMove(Index).Enabled = False
Next Index
End If
'控件可用性
CmdAdd.Enabled = True: CmdModify.Enabled = True: CmdDelete.Enabled = True
CmdCancel.Enabled = False: CmdSave.Enabled = False
End Sub
Private Sub ShowData()
'在文本框中显示数据
If rs.RecordCount <> 0 And rs.EOF = False Then
For Index = 8 To 28
If rs.Fields(Index) <> "" Then
txtItem(Index).Text = rs.Fields(Index)
Else
txtItem(Index).Text = ""
End If
txtItem(Index).Enabled = False
Next Index
End If
End Sub
Private Sub LoadData()
'装载数据
rs = "select * from Indicator order by Serial"
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
End Sub
。。。有DataEnv设计器,需将各TextBox中数据存入Indicator表,并能显示在DataGrid1控件中,数据库连接不会,在线等~解决后有高分相送!
消息还没收到~最好不用ADO,其他模块也没用。 展开
3个回答
展开全部
写代码之前你需要引用ado 控件
具体的办法是添加部件的对话框中选中
microsoft Active Data ...Object control 这句不是很记得怎么写了。
Private Sub command1_click()
dim conn as new adodb.connection
dim rs as new adodb.recordset
dim str as string
dim sql as string
str = App.Path
If Right(str, 1) <> "\" Then
str = str + "\"
End If
str = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & str & "\Indicator.mdb"
conn.open str
rs.cursorlocation=aduseclient
sql="select * from Indicator order by Serial"
rs.open sql,conn,adopenkeyset.adlockpessimistic
上面是连接和打开数据库的代码.
具体的办法是添加部件的对话框中选中
microsoft Active Data ...Object control 这句不是很记得怎么写了。
Private Sub command1_click()
dim conn as new adodb.connection
dim rs as new adodb.recordset
dim str as string
dim sql as string
str = App.Path
If Right(str, 1) <> "\" Then
str = str + "\"
End If
str = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & str & "\Indicator.mdb"
conn.open str
rs.cursorlocation=aduseclient
sql="select * from Indicator order by Serial"
rs.open sql,conn,adopenkeyset.adlockpessimistic
上面是连接和打开数据库的代码.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询