.NET中的记录集 [英] Recordsets in .NET
问题描述
我正在从VB6切换到.NET。在VB6中,您可以使用数据环境和数据控件访问数据
。我发现两者都是完全没用的。我可以用
代码轻松完成相同的任务。例如,如果我想填充文本框,我会这样做:/ b $ b这样的事情:
朦胧作为新记录集
Dim cnn as New Connection
cnn.Open" Provider = Microsoft.Jet.OLEDB.4.0; Data
Source = c:\ test\ test .mdb;"
rst.Open" Select * From Table1",cnn
Text1.Text = rst!Field1
在我看来,使用代码比使用数据环境向导和数据控件使用
更容易,也更灵活。另外,你可以在你的VBA宏中使用
。
我有一个关于.NET的教程,但它似乎只涵盖.NET的版本
数据环境和数据控件。我认为他们称之为服务器
资源管理器和数据适配器。
有没有办法使用直接VB代码访问数据,就像我在
VB6?
谢谢!
查克。
I am making the switch to .NET from VB6. In VB6 you could access data
by using the Data Environment and Data Control. I found both to be
totally useless. I can just as easily accomplish the same task with
code. For example if I wanted to populate a textbox I would do
something like this:
Dim rst As New Recordset
Dim cnn as New Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\test\test.mdb;"
rst.Open "Select * From Table1", cnn
Text1.Text = rst!Field1
Using code, in my opinion, is much easier and more flexible than using
the Data Environment Wizard and the data control. Plus you can use in
in your VBA macros.
I have a tutorial on .NET but it seems to only cover .NET''s version of
the Data Environment and Data control. I think they call it the Server
Explorer and Data Adapter.
Is there a way to access data using straight VB code like I did in
VB6?
Thanks!
Chuck.
推荐答案
你可以在.NET中做同样的事情(我更喜欢那些
拖放向导):
Dim cnn作为OleDbConnection =新的OleDbConnection
(" Provider = Microsoft.Jet.OLEDB.4.0;数据
来源= c:\test\test.mdb;")
cnn.Open()
Dim cmd As OleDbCommand = New OleDbCommand(" Select * From
Table1",cnn)
Dim rdr As OleDbDataReader = cmd.ExecuteReader()
如果rdr.Read()那么
Text1.Text = rdr(0)
结束如果
Bin Song,MCP
You can do the same in .NET (which I prefer over those
drag and drop wizards):
Dim cnn As OleDbConnection = New OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\test\test.mdb;")
cnn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("Select * From
Table1", cnn)
Dim rdr As OleDbDataReader = cmd.ExecuteReader()
If rdr.Read() Then
Text1.Text = rdr(0)
End If
Bin Song, MCP
-----原始消息-----
我我正在从VB6切换到.NET。在VB6中,您可以使用数据环境和数据控件
访问数据。我发现
两者都没用。我可以轻松地完成相同的
任务withcode。例如,如果我想填充一个文本框,我会用这样的东西:
Dim rst作为新的记录集
Dim cnn as new Connection
cnn 。打开Provider = Microsoft.Jet.OLEDB.4.0; Data
Source = c:\\\\test.mdb;"
rst.OpenSelect * From Table1",cnn
Text1.Text = rst!Field1
在我看来,使用代码比使用数据环境向导和数据控件更容易,更灵活。加上
你可以在你的VBA宏中使用。
我有一个关于.NET的教程,但似乎只有
涵盖了.NET的数据环境和数据控件版本。我认为他们将
称为ServerExplorer和数据适配器。
有没有办法使用直接的VB代码访问数据,比如
我在VB6中做过什么?
>谢谢!
Chuck。
。
-----Original Message-----
I am making the switch to .NET from VB6. In VB6 you could access databy using the Data Environment and Data Control. I found both to betotally useless. I can just as easily accomplish the same task withcode. For example if I wanted to populate a textbox I would dosomething like this:
Dim rst As New Recordset
Dim cnn as New Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\test\test.mdb;"
rst.Open "Select * From Table1", cnn
Text1.Text = rst!Field1
Using code, in my opinion, is much easier and more flexible than usingthe Data Environment Wizard and the data control. Plus you can use inin your VBA macros.
I have a tutorial on .NET but it seems to only cover .NET''s version ofthe Data Environment and Data control. I think they call it the ServerExplorer and Data Adapter.
Is there a way to access data using straight VB code like I did inVB6?
Thanks!
Chuck.
.
你好CR,
除了Bing Song一小部分样本,如何将其与数据集一起使用
只需输入您的示例,所以请注意拼写错误。
\ \\\
Hi CR,
In addition to Bing Song a little sample, how to use it with a dataset
Just typed from your example, so watch typos.
\\\\
dim connString as string =" Provider = Microsoft.Jet.OLEDB.4.0; Data
Source = c:\ test\test.mdb;" ;
dim connString as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\test\test.mdb;"
dim SqlString as string =" Select * From Table1"
Dim conn As New OledbConnection(connString)
Dim cmd As New OleDbCommand(sqlStr,Conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(cmd)
da.Fill( ds,Table1)
conn.close
///
我希望这有点帮助。
Cor
dim SqlString as string = "Select * From Table1"
Dim conn As New OledbConnection(connString)
Dim cmd As New OleDbCommand(sqlStr, Conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, "Table1")
conn.close
///
I hope this helps a little bit.
Cor
" Bin Song" <一个******* @ discussions.microsoft.com>在留言新闻中写道:< 02 **************************** @ phx.gbl> ...
谢谢!这给我省了很多麻烦。
"Bin Song" <an*******@discussions.microsoft.com> wrote in message news:<02****************************@phx.gbl>...
Thanks! That saves me a lot of trouble.
你可以在.NET中做同样的事情(我更喜欢那些拖放向导):
(" Provider = Microsoft.Jet.OLEDB.4.0; Data
Source = c:\ test\test.mdb;" )
cnn.Open()
Dim cmd As OleDbCommand = New OleDbCommand(" Select * From
Table1",cnn)
Dim rdr As OleDbDataReader = cmd.ExecuteReader()
如果rdr.Read()那么
Text1.Text = rdr(0)
结束如果
Bin Song,MCP
You can do the same in .NET (which I prefer over those
drag and drop wizards):
Dim cnn As OleDbConnection = New OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\test\test.mdb;")
cnn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("Select * From
Table1", cnn)
Dim rdr As OleDbDataReader = cmd.ExecuteReader()
If rdr.Read() Then
Text1.Text = rdr(0)
End If
Bin Song, MCP
-----原始消息-----
我正在从VB6切换到.NET。在VB6中,您可以使用数据环境和数据控件
-----Original Message-----
I am making the switch to .NET from VB6. In VB6 you could
访问数据
access data
。我发现
都是
完全没用。我可以使用
代码轻松完成相同的
任务。例如,如果我想填充一个文本框,我
code. For example if I wanted to populate a textbox I
会做
这样的事情:
Dim rst作为新记录集
昏暗cnn as New Connection
cnn.Open" Provider = Microsoft.Jet.OLEDB.4.0; Data
Source = c:\ test\test.mdb;"
rst.OpenSelect * From Table1,cnn
Text1.Text = rst!Field1
在我看来,使用代码更容易,更多
something like this:
Dim rst As New Recordset
Dim cnn as New Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\test\test.mdb;"
rst.Open "Select * From Table1", cnn
Text1.Text = rst!Field1
Using code, in my opinion, is much easier and more
数据环境向导和数据控件。加上
the Data Environment Wizard and the data control. Plus
你可以在你的VBA宏中使用
you can use in
。
我有一个关于.NET的教程,但似乎只有
in your VBA macros.
I have a tutorial on .NET but it seems to only
涵盖.NET的
cover .NET''s version of
数据环境和数据控件的版本。我认为他们调用
the Data Environment and Data control. I think they call
它是服务器
资源管理器和数据适配器。
有没有办法使用直接的VB代码访问数据,如
Explorer and Data Adapter.
Is there a way to access data using straight VB code like
我在
VB6中做了什么?
谢谢!
查克。
。
VB6?
Thanks!
Chuck.
.
这篇关于.NET中的记录集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!