i need to get started with accessing a database with c#
please give me the simplest example possible!!
perhaps a mysql database would be the simplest example?
please show me how to connect to a mysql database and get data
i need to get started with accessing a database with c#
please give me the simplest example possible!!
perhaps a mysql database would be the simplest example?
please show me how to connect to a mysql database and get data
This is a decent example of accessing databases in .net from first principles.
If you want to use MySQL, you'll need to get a .Net Data Provider for MySQL or a MySQL ODBC driver.
Or you could install SQL Server Express Edition (free download).
Then just walk through a beginner tutorial, of which there are plenty on the web: MSDN tutorial here, one here, another here, and here is a simple MSDN sample covering ADO, ODBC, OleDB.
Really there is a huge wealth of help out there.
Scott Guthrie wrote a very nice (and lengthly) tutorial on data access using ASP.NET.
To keep things simple, you only need to look at the following:
Guthrie provides code in VB.NET. I'll rewrite the code in C# (which should be placed within the scope of the Page_Load method under Default.aspx):
NorthwindTableAdapters.SuppliersTableAdapter suppliersAdapter =
new NorthwindTableAdapters.SuppliersTableAdapter();
Northwind.SuppliersDataTable suppliers = suppliersAdapter.GetAllSuppliers();
foreach (Northwind.SuppliersRow supplierRow in suppliers)
Response.Write("Supplier: " + supplierRow.CompanyName + "<br />");
By the way, the entire tutorial is worth reading.