如何为一个类创建一个对象并为数据库访问命名空间? [英] how to create an object for a class and name spaces for database access ?

查看:110
本文介绍了如何为一个类创建一个对象并为数据库访问命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为类创建对象并为数据库访问提供名称空间?

how to create an object for a class and name spaces for database access ?

推荐答案

请使其更加详尽. 但是根据我目前的理解,我想您可以在项目中将 LINQ添加到SQL文件.
实体ADO.NET实体数据模型文件
也可以完成相同的操作 如果得到答案,请接受解决方案
谢谢...
please make it more elaborative.
however according to my current understanding i suppose you can add LINQ to SQL file in your project.
same thing can also be done with Entity ADO.NET Entity Data Model File
Accept the solution if you got your answer
thanks...


用于"ms acces数据库"访问,首先您需要在项目中包括以下名称空间.

使用System.Data; //在表单应用程序中已经包含
使用System.Data.OleDb;

现在代码如下:

OleDbConnection con = new OleDbConnection(此处为您的数据库连接字符串(包括@之前的字符串)");

字符串query =这里是您的查询";

OleDbDataAdapter da =新的OleDbDataAdapter(query,con);
DataTable dt = new DataTable();
da.Fill(dt);

//现在您的记录已被获取.
for "ms acces database" access, first you need to include following namespaces in your project.

using System.Data; // in form application it is already included
using System.Data.OleDb;

Now here goes the code:

OleDbConnection con = new OleDbConnection("here your database connection string (including @ before string)");

string query="here your query";

OleDbDataAdapter da=new OleDbDataAdapter(query,con);
DataTable dt=new DataTable();
da.Fill(dt);

//now your record has been fetched.


这篇关于如何为一个类创建一个对象并为数据库访问命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆