c# if string equals database table

I am trying to have c# look to see if the database table equals what i am asking it to equal to open a specific form here is one way i am try doing it

void getsformat()
    {
        string constring = @"server=host;userid=user;password=pass";
        string Query = "select colum from table where callsign= '" + listBox1.SelectedItem + "'";
        MySqlConnection conDataBase = new MySqlConnection(constring);
        MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
        MySqlDataReader myReader;

        try
        {
            conDataBase.Open();
            myReader = cmdDataBase.ExecuteReader();
            while (myReader.Read())
            {
                string sfName = myReader.GetString("sformat");
              }  
            if (sfName == "stworld")
            {
                sendtext = textBox1.Text;
                Form3 f3 = new Form3();
                 f3.Location = new Point(this.Top);

                f3.ShowDialog();  
            }
            else if (sfName == "seperate")
            {
                sendtext = textBox1.Text;
                Form3 f4 = new Form3();
                f4.Location = new Point(this.Top);

                f4.ShowDialog();  
            }


            conDataBase.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }

Open in new window


and the othere way with the "while myreader "end quote after the "if" statement

void getsformat()
    {
        string constring = @"server=host;userid=user;password=pass";
        string Query = "select colum from table where callsign= '" + listBox1.SelectedItem + "'";
        MySqlConnection conDataBase = new MySqlConnection(constring);
        MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
        MySqlDataReader myReader;

        try
        {
            conDataBase.Open();
            myReader = cmdDataBase.ExecuteReader();
            while (myReader.Read())
            {
                string sfName = myReader.GetString("sformat");

            if (sfName == "stworld")
            {
                sendtext = textBox1.Text;
                Form3 f3 = new Form3();
                f3.Location = new Point(this.Top);

                f3.ShowDialog();  
            }
            else if (sfName == "seperate")
            {
                sendtext = textBox1.Text;
                Form3 f4 = new Form3();
                 f4.Location = new Point(this.Top);

                f4.ShowDialog();  
            }

            }
            conDataBase.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }

Open in new window

i cannot get either of them to open a different forms on the different outputs . Any help would be apreciated thank you in advanced
cabalsdemonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Does the while loop ever get entered?
0
cabalsdemonAuthor Commented:
should i use a while loop just for one output
or make an if statement to grab the output
0
cabalsdemonAuthor Commented:
omg i get so ahead of myself sometimes i gues these forums are so you can see your code and correct it well here is what i did wrong

if (myReader["sformat"].ToString() == "stworld")
                {
                    sendtext = textBox1.Text;
                    Form3 f3 = new Form3();
                    //f3.Size = new System.Drawing.Size(500, 500);
                    f3.Location = new Point(this.Top);

                    f3.ShowDialog();  
                }
                    //else if (sfName.ToString() == "seperate")
                    else if (myReader["sformat"].ToString() == "seperate")
                {
                    sendtext = textBox1.Text;
                    Form3 f4 = new Form3();
                    //f3.Size = new System.Drawing.Size(500, 500);
                    f4.Location = new Point(this.Top);

                    f4.ShowDialog();  
                }

Open in new window


i kept calling form 3 and it shoulda been the next form i wanted it to go to
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cabalsdemonAuthor Commented:
ahead of myself sometimes i gues these forums are so you can see your code and correct it
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.