Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

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[^]
 
Share this answer
 
Comments
Maciej Los 19-Dec-13 11:42am    
+5!
Please, see my answer.
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.
 
Share this answer
 
Comments
thatraja 19-Dec-13 12:17pm    
Strongly agree the last line. I should have mentioned that too. 5!
Maciej Los 19-Dec-13 12:21pm    
;)Thank you ;)
krutika.baviskar 20-Dec-13 9:19am    
Than You
Maciej Los 20-Dec-13 9:23am    
You're welcome ;)
[no name] 8-Feb-15 6:32am    
My 5. The first link is great. I was looking always for such a compact overview.
Bruno
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());
}
 
Share this answer
 
Comments
Deepu S Nair 8-Feb-15 3:25am    
Answering old questions adds nothing to the previous solution and is likely to attract
downvoting.
[no name] 8-Feb-15 8:32am    
I don't like to support answer old questions, but in this case it helped at least me to see a very good link in Maciej answer :-)
Bruno

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900