I am fairly new to asp.net, I am trying to connect to a sql (mysql prefferably) database, it must be using C#. I have been searching all of yesterday and today, I cant figure out how. Could someone help me here (if this has been asked, please point me to a topic)

dude u need to create OdbcConnection.

using this object u can connect to any type of db such as (mssql, oracle, mysql, excel...)

dude i amnot sure abt the stability in using mysql with .net.

sam

Do you have anything on it? just saying do an odbc connection doesnt help me.

It solves what to give it, but not on what to put it in. what use is a string with no command?

Does anyone know the answer to my question? it cant be that hard.

I am at my wits end trying to figure this out, does anyone know how to do this?

send me the string u r using and name of ur machine and database name also.

I just figured it out. Thanks for your time

string connectString = @"Data Source=YOURPC\SQLEXPRESS;Initial Catalog=databasename;Integrated Security=True";
SqlConnection con = new SqlConnection(connectString);
con.Open();
string thesql= "select * from product where type_id=" + thistype + " and part_id="+thispart;
SqlCommand cmd = new SqlCommand(thesql, con);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
  string order = reader[2].ToString();
  Response.Write("Order is " + order+ "<br>");
}
reader.Close();
con.Close();

how to connect database in c#? i can't do it. please help me . thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.