1

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

2
  • Lots of factors conspire to make it simpler to connect to MS SQL Server. You may even already have MS SQL Express installed somewhere if you have Visual Studio installed... Commented Apr 26, 2010 at 23:40
  • you are right i have ms sql express installed Commented Apr 26, 2010 at 23:43

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

This is a decent example of accessing databases in .net from first principles.

Comments

0

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:

  1. tutorial 1 - focus on option 2
  2. tutorial 2 - skip the part about advanced options

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.