Click here to Skip to main content
16,017,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Well what I'm trying to do is fill a few textboxes on a list box selection. Here is the code I have:

C#
if(!string.IsNullOrEmpty(this.UserList.SelectedItem.ToString()))
        {
            string value;
            value = UserList.SelectedValue.ToString();
            MySqlCommand sql1 = new MySqlCommand("SELECT * FROM `users` WHERE `name` = ''"+value+"''", myConnection.GetConnection());
            MySqlDataAdapter DA = new MySqlDataAdapter(sql1);
            DataSet DS = new DataSet();
            DA.Fill(DS, "users");
            if(DS.Tables["users"].Rows.Count > 0)
            {
            this.Usernametxtbox.Text = DS.Tables["users"].Rows[0] ["name"].ToString();
            }
            else
            {
               MessageBox.Show("No data to populate the feilds");
            }
        }
        else
        {
         MessageBox.Show("Selected Value is null");
        }
}


And I can't seem to figure out why it's basically telling me I have the wrong Sql syntax, I have checked the Sql query in phpmyadmin and it works fine, so I cant figure out what I'm doing wrong.

Here is the exact error, it highlights DA.Fill(DS, "users"); and then it says You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'System.Data.DataRowView''' at line 1
Posted
Updated 23-Oct-10 11:17am
v2

try this:
MySqlCommand sql1 = new MySqlCommand("SELECT * FROM users WHERE name = '"+value+"'", myConnection.GetConnection());
 
Share this answer
 
I would start by trying this for replacement in your code:

MySqlCommand sql1 = new MySqlCommand("SELECT * FROM users WHERE name = '" + value + "'", myConnection.GetConnection());


also for your table reference:
<br />
this.Usernametxtbox.Text = DS.Tables[0].Rows[0] ["name"].ToString();




Just a thought for testing....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900