我可以毫无问题地发送“显示从属状态”查询,但是将相同的逻辑应用于按钮时什么也不会发生。为什么?
将con重命名为con2
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindData();
}
DataSet ds = new DataSet();
private DataTable dt;
string credentials = @"server=172.22.6.10;user id=system;persistsecurityinfo=True;port=3343;database=mysql;Password=975315";
string sqlQuery = @"show slave status";
string sqlstopstart = @"stop slave;";
public void BindData()
{
//Opens the connection and sends "show slave status" command.
MySqlConnection con = new MySqlConnection(credentials);
con.Open();
MySqlCommand cmd = new MySqlCommand(sqlQuery, con);
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
adp.Fill(ds); //Fill Dataset.
dt = ds.Tables[0]; //Then assign table to dt.
foreach (DataRow dataRow in dt.Rows) //Checks the server if it is running or not.
{
string value = dataRow.Field<string>("Slave_IO_Running");
if (value == "Yes")
{
Label1.Text = "Working";
}
else
{
Label1.Text = "Not Working";
}
}
//Shows a view of the whole query
GridView1.DataSource = dt.DefaultView;
GridView1.DataBind();
}
protected void Button1_Click1(object sender, EventArgs e)
{
MySqlConnection con2 = new MySqlConnection(credentials);
con2.Open();
MySqlCommand cmd = new MySqlCommand(sqlstopstart, con2);
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
}
}
答案 0 :(得分:0)
可能是Button1_Click1事件方法缺少适配器填充并实际执行了sql命令。您可以尝试像在BindData()中那样做类似的事情(如果需要的话,可能实际上重用该方法)