我正在尝试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);
}
}
和#34;以及#34;而myreader"结束" if"声明
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);
}
}
我无法让他们中的任何一个工作。任何帮助都会被贬低 先谢谢你了
答案 0 :(得分:0)
看起来你没有正确设置连接字符串。 这样:
string constring = @"server=host;userid=user;password=pass";
应该有相关信息
string constring = @"server=localhost\SQL2008;userid=myusername;password=mypass";
答案 1 :(得分:0)
在您的select语句中将其更改为
listbox1.selecteditem.tostring();