在VB中把ACCESS的数据读取到TEXT1,TEXT2.。。。中
怎样把ACCESS中的数据读取出来。并显示在VB的TEXT框中。且不可更改(只读属性)要求:1:把ACCESS中的A2显示到。TEXT1中且不可更改。2:把ACCESS中...
怎样把ACCESS中的数据读取出来。并显示在VB的TEXT框中。且不可更改(只读属性) 要求:1: 把ACCESS中的A2显示到。TEXT1中且不可更改。 2: 把ACCESS中的A3现实到。TEXT2中且不可更改。 .......................................
展开
2个回答
2014-01-22
展开全部
Dim myRes As Adodb.Recordset
Dim conn As New Adodb.Connectionconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=你的数据库路径(比如c:\1.mdb);Persist Security Info=False"
conn.OpenSet myRes = conn.Execute("select * from 你的数据库表名")
If Not myRes.EOF Then
Text1.Text = myRes("A2")
text2.Text = myRes("A3")
End If 这样读出来的数据就算是你在TEXT中更改了,也不会影响到数据库,除非你写一条更新SQL才能更改
Dim conn As New Adodb.Connectionconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=你的数据库路径(比如c:\1.mdb);Persist Security Info=False"
conn.OpenSet myRes = conn.Execute("select * from 你的数据库表名")
If Not myRes.EOF Then
Text1.Text = myRes("A2")
text2.Text = myRes("A3")
End If 这样读出来的数据就算是你在TEXT中更改了,也不会影响到数据库,除非你写一条更新SQL才能更改
2014-01-22
展开全部
Dim rs As ADODB.Recordset
Dim cnn As ADODB.Connection
Private Sub Form_Load()
Dim strAppPath As String
Dim constr As String
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
strAppPath = App.Path
If Right(strAppPath, 1) <> "\" Then
strAppPath = strAppPath & "\"
End If
strAppPath = strAppPath & "db1.mdb"
constr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & strAppPath & ""
cnn.Open constr
Dim str As String
str = "select a1,a2 from 表名"
rs.Open str, cnn, adOpenStatic
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text1.Locked = True
Text2.Locked = True
End Sub
Dim cnn As ADODB.Connection
Private Sub Form_Load()
Dim strAppPath As String
Dim constr As String
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
strAppPath = App.Path
If Right(strAppPath, 1) <> "\" Then
strAppPath = strAppPath & "\"
End If
strAppPath = strAppPath & "db1.mdb"
constr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & strAppPath & ""
cnn.Open constr
Dim str As String
str = "select a1,a2 from 表名"
rs.Open str, cnn, adOpenStatic
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
Text1.Locked = True
Text2.Locked = True
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询