• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[C#] How can i make a database connection?

Newbie Spellweaver
Joined
Dec 6, 2010
Messages
31
Reaction score
10
Hello guys, im really bad right now. I can't get my GUI connect to my extern Database. Its hosted on my own host, so how can i make a connection to the host, + a QUERY? Like if it connects, that it makes the Query what ive put in the textbox1?
Example:
Console.Command = "" + textbox1.text + "";
or
Console.Command = (textbox1.Text);
or something else, +
in the textbox i did write example: "SELECT pixels FROM users WHERE id = 1;"

Thanks in advance :p
 
Custom Title Activated
Loyal Member
Joined
Nov 27, 2009
Messages
1,905
Reaction score
948
Hello guys, im really bad right now. I can't get my GUI connect to my extern Database. Its hosted on my own host, so how can i make a connection to the host, + a QUERY? Like if it connects, that it makes the Query what ive put in the textbox1?
Example:
Console.Command = "" + textbox1.text + "";
or
Console.Command = (textbox1.Text);
or something else, +
in the textbox i did write example: "SELECT pixels FROM users WHERE id = 1;"

Thanks in advance :p
read this article
Tutorial - Using MySQL in C# - C#
helped me out a lot :p

just get the connecter (MySql.Data.dll) + add it to references then just copy the code and modify it to your needs
Console.writeLine("HOST");
string host = Console.readLine();
Console.writeLine("USER");
string user = Console.readLine();
Console.writeLine("PASS");
string pass = Console.readLine();
Console.writeLine("DB");
string db = Console.readLine();
string conString = "server=" + host + ";userid=" + user + ";password=" + pass + ";database=" + db + "";
 
Last edited:
WHOOOOOO
Loyal Member
Joined
May 21, 2008
Messages
960
Reaction score
47
Moved to coder's paradise. Reckon you can get more help here. Good luck!
 
It won't fit
Loyal Member
Joined
May 18, 2007
Messages
1,789
Reaction score
291
read this article
Tutorial - Using MySQL in C# - C#
helped me out a lot :p

just get the connecter (MySql.Data.dll) + add it to references then just copy the code and modify it to your needs
Console.writeLine("HOST");
string host = Console.readLine();
Console.writeLine("USER");
string user = Console.readLine();
Console.writeLine("PASS");
string pass = Console.readLine();
Console.writeLine("DB");
string db = Console.readLine();
string conString = "server=" + host + ";userid=" + user + ";password=" + pass + ";database=" + db + "";


You don't even need the connector installed. You just need that file. I used it recently without connector installed and it still worked the same way. :)

Just a tid bit
 
Joined
Jan 27, 2007
Messages
1,201
Reaction score
1,067
Not trying to be rude or anything but you could have googled mySQL in c#, there are tons of results to do with mySQL in .NET languages.

@Abysmal That's because the DLL imports the mySQL class into your project as service reference that way you don't have to use the connector. It's better for people who know what their doing, the connector pools connections for you automatically but using the DLL you have to do it yourself, if you want optimal performance.
 
Experienced Elementalist
Joined
Apr 12, 2009
Messages
241
Reaction score
32
fyi, you can use linq-to-sql... just drag and drop tables into the designer... and you can access your code like

int? user_id = Users.Where(x=>x.UserName=="Jim" && x.Password=="coolpw").Select(x=>x.UserID).SingleOrDefault();
 
Experienced Elementalist
Joined
Apr 12, 2009
Messages
241
Reaction score
32
*ahem*.

Garbage COLLECTED .net language, you mean ;) hehe
 
Custom Title Activated
Loyal Member
Joined
Apr 8, 2008
Messages
1,125
Reaction score
330
... Or you can make your own little databases VIA data sources.
 
Back
Top