数据库连接使用wpf访问,excel,sql,oracle,sqlite。 [英] Database Connection with access,excel,sql,oracle,sqlite using wpf.

查看:219
本文介绍了数据库连接使用wpf访问,excel,sql,oracle,sqlite。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的wpf应用程序中插入和获取来自Access,Excel,SQL,Oracle等各种数据源的数据。我有一个应用程序,用户选择数据库文件(他想要的任何文件,例如abc.mdb或abc.xls或abc.dbf),这些文件中的数据将显示在griedview中。我认为ODBC连接是可选的,但我不确定。我是初学者,所以请用一些简单的例子帮助我解决这个问题。

I want to insert and fetch the data from various datasources like Access, Excel, SQL, Oracle in my wpf application. I have an application in which user selects database file(whichever file he wants, for eg. abc.mdb or abc.xls or abc.dbf)and the data from these files is to be displayed in griedview. I think ODBC connection is the option for that, but am not sure about it. I am a beginner, so please help me to solve this problem wit some simple example.

推荐答案

你需要做的就是创建图层和放大器。多个数据源的连接字符串。



首先学习如何在WPF中进行CRUD操作。实践一段时间&然后继续支持多个数据源的过程。这里有一个WPF CRUD样本

在WPF中的DataGrid中的CRUD操作 [ ^ ]



这里有一个多个数据源的示例(但它不在WPF中,但你可以在这里学习概念)

插入,更新,删除在ASP.NET Gridview中,DataSource作为SQL Server,MS Access(mdb / accdb),XML和Framework作为2.0 / 3.0 / 3.5 / 4.0(VS 2005/2008/2010) [ ^ ]



您可以在网上找到更多样品。 需要教育 [ ^ ]
All you need to do is create layers & connectionstrings for multiple datasources.

First learn how to do CRUD operation in WPF. Practice that for a while & then go ahead with process of supporting multiple datasources. Here a sample for WPF CRUD
CRUD Operation In DataGrid In WPF[^]

And here a sample for multiple datasources(but it's not in WPF, but you could learn concepts here)
Insert, Update, Delete in ASP.NET Gridview, DataSource as SQL Server, MS Access (mdb/accdb), XML and Framework as 2.0 / 3.0 / 3.5 / 4.0 (VS 2005/2008/2010)[^]

You could find more samples in web. And Education Needed[^]


Thatraja的Solution1很好,并解释了如何使用多个数据库创建WPF应用程序。



我想提供更多细节...



首先,它赢了'太容易了。为什么?有几个resons,但最重要的是,每个 .NET框架数据提供程序 [ ^ ]有自己的一组对象,方法等。按照链接查找。



当然,你可以尝试写超级通用 - 数据访问层 [ ^ ]with 重载方法 [ ^ ]以插入,选择,更新和删除数据。应将连接对象作为输入参数传递。



我的建议:不要那样做。有太多事情要犯错误。最好将注意力集中在一个,也许是两个数据库。
Solution1 by thatraja is good and explains how to create WPF application with multiple databases.

I would like to provide some more details...

First of all, it won't be so easy. Why? There are several resons, but the most important is that, that each .NET Framework Data Provider[^] has got own set of objects, methods, etc. Follow the link to find out.

Of course, you can try to write "super-universal-Data-Access-Layer[^]" with overloaded methods[^] to insert, select, update and delete data. A connection object should be passed as an input parameter.

My advice: don't do that. There is too many things to make a mistake. Better move your focus on one, maybe two, databases.


与oracle我使用此代码希望它能帮助你



首先是广告引用 Oracle.DataAccess

然后addind命名空间使用 Oracle.DataAccess.Client;

并使用以下内容代码

尝试

{

string MyConString =Data Source = localhost; User Id = yourusername; Password = yourpassword;;

使用(OracleConnection连接=新的OracleConnection(MyConString))

{

connection.Open();

sqldb1 =select * from DEMO_CUSTOMERS;;

using(OracleCommand cmdSe1 = new OracleCommand(sqldb1,connection))

{

DataTable dt = new DataTable();

OracleDataAdapter da = new OracleDataAdapter(cmdSe1);

da.Fill(dt);

db1.ItemsSource = dt.DefaultView;

}

connection.Close();



}

catch(Exception ex)

{

MessageBox.Show(ex.ToString());

}
with oracle i use this code hope it will help you

firstly ad reference Oracle.DataAccess
then addind namespace using Oracle.DataAccess.Client;
And using the following code
try
{
string MyConString = "Data Source=localhost;User Id= yourusername;Password=yourpassword;";
using (OracleConnection connection = new OracleConnection(MyConString))
{
connection.Open();
sqldb1 = "select * from DEMO_CUSTOMERS;";
using (OracleCommand cmdSe1 = new OracleCommand(sqldb1, connection))
{
DataTable dt = new DataTable();
OracleDataAdapter da = new OracleDataAdapter(cmdSe1);
da.Fill(dt);
db1.ItemsSource = dt.DefaultView;
}
connection.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}


这篇关于数据库连接使用wpf访问,excel,sql,oracle,sqlite。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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