Morning guyz,I need to create a conditional state ment using(if) to ask a statement to execute if content equals a string value and its not working.
This is what I mean

if(cboemployee=="All fieds")
{
 mysqlconnection sql = new mysqlconnection();
            sql.createconn();
            sql.command = sql.connection.CreateCommand();
                                               
               
                    sql.createconn();
                   sql.command = sql.connection.CreateCommand();
                   sql.command.CommandText ="  INSERT INTO Result(Name,Address,phn,Sex,Position) SELECT Name,Address,phn,Sex,position FROM Employee_data ";
                  MessageBox.Show("done");

                   sql.command.ExecuteNonQuery();
                   sql.connection.Close();
                   sql.connection.Dispose();
}

its working without if but when I but if it becomes static plz help now.

what are you suppose to check here?

if(cboemployee=="All fieds")

I wjust wanted to check if the picked option from the combo was "All fieds"

You cn do it this way:

if(cboemployee.SelectedItem.ToString().Equals("All fields"))
{
     //if it does, your code in here
}

or this way:

if(cboemployee.SelectedItem.ToString() == "All fields")
{
     //if it does, your code in here
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.