Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 06:57

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C#]need Help in MySql

Discussion on [C#]need Help in MySql within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
wolfvb's Avatar
 
elite*gold: 0
Join Date: Nov 2010
Posts: 238
Received Thanks: 218
[C#]need Help in MySql

hi all i need some help in mysql things in C# i done the connection part
by this but ineed some help in how to get data from database
PHP Code:
 MySqlConnection conn = new MySqlConnection();
conn = new MySqlConnection();
conn.ConnectionString "server=" cbServerSelect.Text ";" "user id=" txtUserInput.Text ";" "password=" txtPassInput.Text ";" "database=my";
if (
cbServerSelect.Text == "" || txtUserInput.Text == "" || txtPassInput.Text == "")
{
 
MessageBox.Show("All Fields must be entered");
 }
else
{
try
{
conn.Open();
MessageBox.Show("Connection Opened Successfully");
conn.Close();
 }
 catch (
Exception ex)
{
MessageBox.Show("Error Connecting to MySQL DB" "\r\n" +  "\r\n" ex.Message);
}

i need some code like how to get data from tables and insert in it
so pleas i need some help
i get a code to get data but it make a problem when get names get it like this
PHP Code:
System.Byte[] 
the code
PHP Code:
MySqlDataReader Reader;
MySqlCommand command conn.CreateCommand();
command.CommandText "select name from account";
conn.Open();
Reader command.ExecuteReader();
while (
Reader.Read())
{
string thisrow "";
for (
int l 0Reader.FieldCountl++)
thisrow += Reader.GetValue(l) + "";
comboBox1.Items.Add(thisrow);
listBox1.Items.Add(thisrow);
}
conn.Close(); 
Sorry For that because am not too good in Coding i learn every thing i know in it from internet

wolfvb is offline  
Old 03/27/2012, 09:21   #2
 
elite*gold: 456
Join Date: Jan 2011
Posts: 18
Received Thanks: 4
To insert data:

Code:
//How I open the connection:
ConnectionString = "SERVER=" + parmarr[0] + ";" +
                                  "DATABASE=" + parmarr[1] + ";" +
                                  "UID=" + parmarr[2] + ";" +
                                  "PASSWORD=" + parmarr[3] + ";";

MySqlConnection connection = new MySqlConnection(ConnectionString);
connection.Open();
MySqlCommand command = connection.CreateCommand();

//Here is the imortant part:
command.CommandText = "INSERT INTO mytable (column1,column2) VALUES ('test', 'test2')";
 command.ExecuteNonQuery();
//----

//Close the connection:
command.Dispose();
connection.Close();
connection.Dispose();
And to get data:
Code:
ConnectionString = "SERVER=" + parmarr[0] + ";" +
                                  "DATABASE=" + parmarr[1] + ";" +
                                  "UID=" + parmarr[2] + ";" +
                                  "PASSWORD=" + parmarr[3] + ";";

connection = new MySqlConnection(ConnectionString);
connection.Open();
command = connection.CreateCommand();

command.CommandText = "SELECT name FROM account;"
MySqlDataReader reader = command.ExecuteReader();

while(reader.Read())
{
//Whatever you want to do with the data...
string mystring = reader[0].ToString(); //I think this is what you need instead of Reader.GetValue()
}
reader.Close(); //Very important! You can't do another MySQL operation before you close the reader.
command.Dispose();
connection.Close();
connection.Dispose();
I haven't tested the code, but it should work...
I think the way you
cin0s is offline  
Thanks
1 User
Old 03/27/2012, 18:10   #3
 
wolfvb's Avatar
 
elite*gold: 0
Join Date: Nov 2010
Posts: 238
Received Thanks: 218
i will test it and see if it work any way work or no thanks for your time and for your help
regard wolfvb

PHP Code:
 while (Reader.Read())
                   {
                       
// string to get the data in row
                       
string thisrow "";
                       
//this loop work on columns
                       // in our example we have id,name,phone

                       
string mystring Reader[0].ToString(); //I think this is what you need instead of Reader.GetValue()
                           
thisrow += Reader.GetValue(0) + "";
                       
// we add the data in single row to listbox
                       
comboBox1.Items.Add(thisrow);
                       
listBox1.Items.Add(thisrow);
                   }
reader.Close(); //Very important! You can't do another MySQL operation before you close the reader.
command.Dispose();
connection.Close();
connection.Dispose(); 
its have same problem get names
in same way
PHP Code:
System.Byte[] 
so any ideas its a privet server db Eo DB if this make any changes in codes
and there is a problem in this too
PHP Code:
MySqlConnection conn = new MySqlConnection();
            
conn = new MySqlConnection();
            
conn.ConnectionString "server=" cbServerSelect.Text ";" "user id=" txtUserInput.Text ";" "password=" txtPassInput.Text ";" "database=my";



            
MySqlCommand command conn.CreateCommand();
            
//Here is the imortant part:
            
command.CommandText "UPDATE `cq_user` SET `name`='wolfvb[PM]' WHERE (`name`='[GM]~Ev!l~[PM]')";
            
command.ExecuteNonQuery();
            
//----

            //Close the connection:
            
command.Dispose();
            
conn.Close();
            
conn.Dispose(); 
the problem in here
PHP Code:
command.ExecuteNonQuery(); 
wolfvb is offline  
Old 03/27/2012, 18:42   #4
 
elite*gold: 456
Join Date: Jan 2011
Posts: 18
Received Thanks: 4
Ok. You want to have all "name"s form the table "account" in a listbox. Right?

Try this:
Code:
command.CommandText = "SELECT name FROM account";
Reader = command.ExecuteReader();
while (Reader.Read())
{
listBox1.Items.Add(Reader[0].ToString());
}
I seriously don't know what you want to do with the for loop if you reade only one column from the database...
cin0s is offline  
Thanks
1 User
Old 03/27/2012, 19:11   #5
 
wolfvb's Avatar
 
elite*gold: 0
Join Date: Nov 2010
Posts: 238
Received Thanks: 218
**** the same problem i don't know why its get name like that

the insert part working good now with no problem the only problem here now
wolfvb is offline  
Old 03/27/2012, 19:56   #6
 
elite*gold: 456
Join Date: Jan 2011
Posts: 18
Received Thanks: 4
Are you sure that the insert part work correctly? Please look with a tool like phpmyadmin or something else, if the data in the database is correct.
Maybe "System.Byte[]" is written in every Row of the table...
cin0s is offline  
Thanks
1 User
Old 03/27/2012, 20:42   #7
 
wolfvb's Avatar
 
elite*gold: 0
Join Date: Nov 2010
Posts: 238
Received Thanks: 218
i use Navicat to mage the db
and this is the table account and yeas the insert part work good i test it 3 times and work very good this a pic from table account
wolfvb is offline  
Old 03/27/2012, 20:54   #8
 
elite*gold: 456
Join Date: Jan 2011
Posts: 18
Received Thanks: 4
You use the MySQL Connector Net Assemblie "MySql.Data.dll". Right?

Is "name" a varchar?
Try to read a integer from the db (for example "pointtime") [I think it's a a int...]
cin0s is offline  
Old 03/27/2012, 21:15   #9
 
wolfvb's Avatar
 
elite*gold: 0
Join Date: Nov 2010
Posts: 238
Received Thanks: 218
its get numbers well with no problem so it get "id,etc.." well but in passsword and names this problem happen
wolfvb is offline  
Old 03/27/2012, 21:50   #10
 
elite*gold: 456
Join Date: Jan 2011
Posts: 18
Received Thanks: 4
Do you create the table in the code? For example:
"CREATE TABLE IF NOT EXISTS user (id INT NOT NULL AUTO_INCREMENT, name VARCHAR (256), password VARCHAR (256), PRIMARY KEY (id));" ?

Could you post this string?
cin0s is offline  
Old 03/28/2012, 01:11   #11
 
wolfvb's Avatar
 
elite*gold: 0
Join Date: Nov 2010
Posts: 238
Received Thanks: 218
there is the string
PHP Code:
CREATE TABLE `account` (
  `
idint(4unsigned zerofill NOT NULL auto_increment,
  `
namevarchar(32binary NOT NULL default '',
  `
passwordvarchar(32binary NOT NULL default '',
  `
typeint(4unsigned NOT NULL default '0',
  `
pointint(4) default '0',
  `
pointtimeint(4unsigned zerofill NOT NULL default '20020318',
  `
onlineint(4unsigned zerofill NOT NULL default '0000',
  `
reg_datedatetime default NULL,
  `
licenceint(4unsigned default '0',
  `
reg_flagbigint(12unsigned default '3',
  `
netbar_ipvarchar(15) default '127.0.0.1',
  `
ip_maskvarchar(15) default '255.255.255.255',
  `
add_typesmallint(1unsigned zerofill NOT NULL default '0',
  `
VIPint(4unsigned NOT NULL default '3',
  `
offlineint(4) default NULL,
  `
pwdvarchar(32) default NULL,
  `
idnumvarchar(20) default NULL,
  `
emailvarchar(32) default NULL,
  
PRIMARY KEY  (`id`),
  
UNIQUE KEY `index_name_pass` (`name`,`password`),
  
UNIQUE KEY `index_username` (`name`),
  
KEY `index_type` (`type`),
  
KEY `index_regtype` (`reg_flag`),
  
KEY `index_isp` (`type`,`netbar_ip`),
  
KEY `typereg` (`type`,`reg_date`)
TYPE=MyISAM
wolfvb is offline  
Old 03/28/2012, 08:33   #12
 
elite*gold: 456
Join Date: Jan 2011
Posts: 18
Received Thanks: 4
Quote:
The BINARY and VARBINARY types are similar to CHAR and VARCHAR, except that they contain binary strings rather than nonbinary strings.


Try to convert the bytearray you get into a string.
listBox1.Items.Add(System.Text.ASCIIEncoding.GetSt ring(Reader[0])) or listBox1.Items.Add(System.Text.ASCIIEncoding.GetSt ring(Reader[0].ToString()))
(not sure which one) should do it...


If this doesn't work delte the word 'binary' in your CREATE TABLE string and create the table new.
cin0s is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
[ERROR] Mysql can't connect to local Mysql server through socket
10/08/2011 - Metin2 Private Server - 3 Replies
Hallo Liebe Com, Undzwar habe ich ein Problem mit Mysql. Als ich Mysql installiert habe konnte ich Problemlos drauf connecten,auch mit navicat.Aber als ich die Serverfiles (2011er) installiert habe und rebootet habe ging aufeinmal mysql nichtmehr.Wenn ich mysql -p eingebe steht dann da: Wenn ich den Startbefehl eingebe steht da: Was kann das sein? Und es passiert immer nur nach der Serverfiles installation. Ich habe den Server schon 3x resetten lassen und es passierte immer das...
[MYSQL dont Start]su: unknown login: mysql
05/08/2011 - Metin2 Private Server - 2 Replies
Moin Leute und zwar hab ich ein Problem das ich bis heute noch nie hatte, Ich hab mein Root Server neu gestartet und dabei bemerkt das der Mysql Server nicht wieder mit hoch gefahren ist..... Dann hab ich versucht per: ihn wieder zu starten aber es gibt mir nur das hier aus: Die Frage ist jetzt an was liegt das? Danke schonmal.
[ERROR] Mysql can't connect to local Mysql server through socket
11/06/2010 - Metin2 Private Server - 5 Replies
I just recently tried to configure a DNS server for MT2.. It came up with this error ERROR: 2002 (HY000): Can't connect to local Mysql server through socket '/tmp/mysql.sock' (2) Do I need to do a fresh installation of FBSD? :S Thanks.
MySQL Navicat 1130-Host'5.xxx.xx.xxx' is not allowed to connect to the MySQL Server
08/07/2010 - Metin2 Private Server - 14 Replies
Hallo com, ich habe ein Problem mit Navicat. Undzwar habe ich diesen Fehler hier : "1130-Host'5.xxx.xx.xxx' is not allowed to connect to the MySQL Server" seid gestern. Ich dachte mir mal ich änder mein Navicat Passwort um... Als ich dies getan habe, und meinen Server rebootet habe und Navicat neugestartet habe, und ich mich wieder in Navicat einloggen wollte kam diese Fehlermeldung. Nun habe ich das Problem das ich mich nicht mehr mit Navicat connecten kann. Habe schon alles versucht...



All times are GMT +1. The time now is 06:59.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.