Connecting to a database using a WPF application

15,080

Solution 1

Check this: EF code first with oracle, mysql, etc.

At the end, there is download link for a sample.

As for WPF, i would recommend to read some tutorials if you´re not familiar with it. Searching for WPF and EF together will lead to a lot of more or less helpful tutorials and blogs, etc. But i would recommend playing around with the Entityframework and the code-first approach first.

Solution 2

Setting up Entity Framework takes too long + Compatibility issues, thus not efficient. Use this:

 SqlConnection connection = new SqlConnection
 {
      ConnectionString = ConfigurationManager.ConnectionStrings["Connection_String_Name"].ConnectionString
 };

 connection.Open();

 SqlCommand cmd = new SqlCommand("Query_For_What_You_Wanna_Do");
 cmd.ExecuteNonQuery();

 connection.Close();
Share:
15,080
Asaf
Author by

Asaf

I'm a language-fanatic, an anime/manga fan, and an avid gamer. Also, I'm super interested in programming languages and hope to someday make it my job. I currently know/study: Japanese (advanced level) Korean (just started) Hebrew (mother tongue) English (judge for yourself) PHP, HTML5 + CSS3, Java, Javascript, C# I usually +1 everyone who comments/answers (unless I forget!) as I feel anyone who takes their time to answer a question deserves to be credited for it in some way. Especially when they don't necessarily get paid for it.

Updated on June 14, 2022

Comments

  • Asaf
    Asaf almost 2 years

    I've started getting into WPF not so long ago.
    As I'm in the stage of learning MVVM, I'm using THIS tutorial.

    Following that tutorial I now have a basic project that involves products.
    The next thing I want to do, is learn how to connect to a database and store/retrieve information from it.

    My question is, what are the available ways to connect to a database? what is the best, efficient way to do it?

    Also, can WPF applications connect to an hosted mysql database (the ones used for websites)?

    I'm using VS2012 if that makes any difference.

    Excuse my newbie-ness! I'm still just a beginner! Thank you in advance!