Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to write a local program management and install system for my home network, and I think I've got the technologies nailed down:

  • C#/.NET/WPF for the client
  • Lua for installation scripting support (through LuaInterface)
  • SQL Server Express for maintaining a database of programs

However I'm unsure what specifically I'll use to connect C# to the database. Is there something built into the .NET framework for this? Bonus points if you have a suggestion on what I should use for interacting with said database.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
209 views
Welcome To Ask or Share your Answers For Others

1 Answer

Check out

I'm sure there's plenty more out there - just google for "ADO.NET" and "Tutorial" ......

UPDATE:

If you want to connect to your local SQL Server Express, and connect to the "Northwind" database, and read the top 5 customers from the "Customers" table, you'd have to do something like this:

string connectionString = "server=(local)SQLExpress;database=Northwind;integrated Security=SSPI;";

using(SqlConnection _con = new SqlConnection(connectionString))
{
   string queryStatement = "SELECT TOP 5 * FROM dbo.Customers ORDER BY CustomerID";

   using(SqlCommand _cmd = new SqlCommand(queryStatement, _con))
   {
      DataTable customerTable = new DataTable("Top5Customers");

      SqlDataAdapter _dap = new SqlDataAdapter(_cmd);

      _con.Open();
      _dap.Fill(customerTable);
      _con.Close();

   }
}

Now you would have all 5 top customers from your Northwind database in the DataTable and you can inspect them, print them out, manipulate them - whatever you want to do.

That's ADO.NET in action!

As for the details of the connection string - what options you can use and what it should look like, check out the Connection Strings web site - it has tons of examples and explanations.

Marc


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...