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 = 0; l < Reader.FieldCount; l++) 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
//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
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
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();
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...
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...
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
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));" ?
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.
[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...