数据集,连接,访问数据库 [英] Dataset , Connection , Access Data Base
本文介绍了数据集,连接,访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过编写代码连接到数据库访问和设置数据集(无向导)?
示例:我可以连接数据库按此代码:
how can i Connect to data base Access And Set DataSet (Without Wizard) By Writing Code ?
Example: I can connect Data base By This Code :
Dim da As New OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim con As OleDb.OleDbConnection
Dim con_str As String = "provider=microsoft.jet.oledb.4.0;data source=e:\damyar.mdb;"
con.ConnectionString = con_str
con.Open()
现在我有一个DataGridView,我想通过(CON)连接和表(表1)填充数据集(DS),然后通过(DS)填充数据网格
注意:不要使用向导,只是编写代码
Now i Have a DataGridView , i want Fill Dataset(DS) by (CON) Connection And Table (Table1) , Then Fill Datagrid by (DS)
NOTE : Dont Use Wizard , Just Writing Code
推荐答案
这看起来很像家庭作业,所以没有代码!
1)创建一个SQL SELECT语句:SELECT * FROM MyTable将执行,其中MyTable是要访问的表的名称。
2)创建OleDbDataAdapter,并且使用select语句和你的连接来创建一个新实例。
3)创建一个DataSet对象,并为其分配一个新实例。
4)填写DataSet OleDbDataAdapter(提示:使用Fill方法)
5)将DataGridView DataSource属性设置为DataSet中的第一个表。
This looks suspiciously like homework, so no code!
1) Create an SQL SELECT statement: "SELECT * FROM MyTable" will do, where MyTable is the name of the table to want to access.
2) Create an OleDbDataAdapter, and use the select statement and your connection to create a new instance.
3) Create a DataSet object, and assign a new instance to it.
4) Fill the DataSet from the OleDbDataAdapter (HINT: use the Fill method)
5) Set the DataGridView DataSource property to the first table in the DataSet.
HI HOW DID如何创建DATASET IN VB.NET CODEING&FORMS
HI HOW DID CREATE DATASET IN VB.NET CODEING & FORMS
这篇关于数据集,连接,访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文