4个回答
2013-08-26
展开全部
比较简单的方法:
1.在窗体上添加一个TextBox控件(Text1),一个Data控件(Data1);
2.设置Data1的DatabaseName为数据库文件,设置RecordSource为需要关联的表;
3.设置Text1的DataSource为Data1,设置DataField为需要关联的列名.
注:以上方法仅使用与Access,Excel等,但不能用于连接SQL Server.
1.在窗体上添加一个TextBox控件(Text1),一个Data控件(Data1);
2.设置Data1的DatabaseName为数据库文件,设置RecordSource为需要关联的表;
3.设置Text1的DataSource为Data1,设置DataField为需要关联的列名.
注:以上方法仅使用与Access,Excel等,但不能用于连接SQL Server.
2013-08-26
展开全部
下面是一个例子:
1.工程->引用"Mircosoft ActiveX Data Objects 2.5 Library";
2.窗体上添加2个CommandButton(Comman1和Command2)一个TextBox(Text1);
3.代码:
Option Explicit
Dim con As Connection
Dim rs As Recordset
Private Sub Command1_Click() '下一条记录
rs.MoveNext
Command2.Enabled = True
If rs.EOF Then
Command1.Enabled = False
Exit Sub
End If
Text1.Text = rs("number").Value
End Sub
Private Sub Command2_Click() '上一条记录
rs.MovePrevious
Command1.Enabled = True
If rs.BOF Then
Command2.Enabled = False
Exit Sub
End If
Text1.Text = rs("number").Value
End Sub
Private Sub Form_Load()
Command2.Enabled = False
Set con = New Connection
con.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;data source=" & _
"F:\db1.mdb;" '换成你的路径
con.Open
Set rs = New Recordset
rs.Open "select * from t1", con, adOpenDynamic, adLockOptimistic '这里要设置好游标
If rs.EOF And rs.BOF Then
Text1.Text = ""
Command1.Enabled = False
Else
Command1.Enabled = True
rs.MoveFirst
Text1.Text = rs("number").Value '绑定内容
End If
End Sub
1.工程->引用"Mircosoft ActiveX Data Objects 2.5 Library";
2.窗体上添加2个CommandButton(Comman1和Command2)一个TextBox(Text1);
3.代码:
Option Explicit
Dim con As Connection
Dim rs As Recordset
Private Sub Command1_Click() '下一条记录
rs.MoveNext
Command2.Enabled = True
If rs.EOF Then
Command1.Enabled = False
Exit Sub
End If
Text1.Text = rs("number").Value
End Sub
Private Sub Command2_Click() '上一条记录
rs.MovePrevious
Command1.Enabled = True
If rs.BOF Then
Command2.Enabled = False
Exit Sub
End If
Text1.Text = rs("number").Value
End Sub
Private Sub Form_Load()
Command2.Enabled = False
Set con = New Connection
con.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;data source=" & _
"F:\db1.mdb;" '换成你的路径
con.Open
Set rs = New Recordset
rs.Open "select * from t1", con, adOpenDynamic, adLockOptimistic '这里要设置好游标
If rs.EOF And rs.BOF Then
Text1.Text = ""
Command1.Enabled = False
Else
Command1.Enabled = True
rs.MoveFirst
Text1.Text = rs("number").Value '绑定内容
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-26
展开全部
xh.Text = Me.DateDataSet.Tables("学生信息").Rows(0)(0).ToString()
这是表,有行也有列的,除了指明行,要还指明列,后面加tostring把结果转换为string类型.
这是表,有行也有列的,除了指明行,要还指明列,后面加tostring把结果转换为string类型.
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-26
展开全部
把文本框的DataSource属性设置为数据库对象(data)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询