User1
User1

Reputation: 57

Mysql query not working in C# but does in MySql Work Bench

Would anyone be able to explain to me why this MySQL query doesn't work, I have tested the query in MySQL Work Bench and it works fine, I have also used the same C# code many times in other parts of this form application to pass the Data Base a query and that also works fine. Thanks.

public void addComboBox(ref Dictionary<string, string> folders)
            {
                comboBox1.Items.Clear();
                comboBox2.Items.Clear();
                string sqlGetFolders = "Select FolderName, FolderPath From folder, users Where folder.ID = users.ID and folder.ID = '@uID';";
                MySqlCommand command = new MySqlCommand(sqlGetFolders, connection);
                command.Parameters.AddWithValue("@uID", ID);
                MySqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)//bugging purposes
                {
                    MessageBox.Show("Has Rows");//bugging purposes
                    while (reader.Read())
                    {
                        folders.Add((reader[0]).ToString(), (reader[1]).ToString());//folders is a dictionary 
                        comboBox1.Items.Add((reader[0]).ToString());//lists
                        comboBox2.Items.Add((reader[0]).ToString());//lists
                        MessageBox.Show((reader[0]).ToString());//bugging purposes
                    }
                }
                else
                {
                    MessageBox.Show("No Rows");//bugging purposes
                }
                reader.Close();
            }

Upvotes: 1

Views: 237

Answers (1)

mybirthname
mybirthname

Reputation: 18127

string sqlGetFolders = "Select FolderName, FolderPath From folder, users Where folder.ID = users.ID and folder.ID = @uID";

Your @uID parameter should not be in quotes. The quotes will be added automatically when the parameters are added.

Upvotes: 2

Related Questions