954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Connection to sql database in c#

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)

Village Idiot
Newbie Poster
5 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

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

web_developer
Junior Poster in Training
84 posts since Mar 2006
Reputation Points: 10
Solved Threads: 1
 

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

Village Idiot
Newbie Poster
5 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

go to connectionstrings.com,will solve all ur problems related to connection.tell me if you got your problem solved

amithasija
Light Poster
44 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

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.

Village Idiot
Newbie Poster
5 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

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

Village Idiot
Newbie Poster
5 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

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

amithasija
Light Poster
44 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

I just figured it out. Thanks for your time

Village Idiot
Newbie Poster
5 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 
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+ "");
}
reader.Close();
con.Close();
hhd
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You