我想c#
看看数据库是否table
等于我要求它等于打开一个特定的表单这是我尝试做的一种方式
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);
}
}
以及在“if”语句之后使用“while myreader”结束引用的另一种方式
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);
}
}
我不能让他们中的任何一个工作。任何帮助将不胜感激