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:
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.
Database Connectivity using C/C++ This IDE is specially designed for C and C++ and easy to use. SQLAPI++ is a C++ library (basically a set of header files) for accessing multiple SQL databases (Oracle, SQL Server, DB2, Sybase, Informix, InterBase, SQLBase, MySQL, PostgreSQL, SQLite, SQL Anywhere and ODBC).
You can code SQL statements in a C or C++ program wherever you can use executable statements. Each SQL statement in a C or C++ program must begin with EXEC SQL and end with a semicolon (;). The EXEC and SQL keywords must appear on one line, but the remainder of the statement can appear on subsequent lines.
Connect to a SQL Server instance Start SQL Server Management Studio. The first time you run SSMS, the Connect to Server window opens. If it doesn't open, you can open it manually by selecting Object Explorer > Connect > Database Engine. For Server type, select Database Engine (usually the default option).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With