1

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();
            }

1 Answer 1

2
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.

Sign up to request clarification or add additional context in comments.

2 Comments

Wow that was easy, Thanks.
@User1 you are welcome you can mark the question as correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.