我遇到了錯誤「連接必須有效,並再次打開,當我更改我的sql查詢代碼。任何人都可以幫忙??(編輯)在form1中,我已連接到數據庫在窗口2我想補充的查詢。連接必須有效並再次打開
//IN Class1.cs
public void test(string query, string name)
{
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(query, connection);
cmd.CommandText = @query;
cmd.Parameters.AddWithValue("Name", name);
MySql.Data.MySqlClient.MySqlDataReader Reader = cmd.ExecuteReader();
while (Reader.Read())
{
Console.WriteLine(Reader[0]);
}
cmd.ExecuteNonQuery();
}
//IN Form2.cs
private void button2_Click(object sender, EventArgs e)
{
name = textBox1.Text;
var obj = new Class1();
obj.test(@"SELECT * FROM players WHERE name = ?Name;", name);
}
它在FORM1中打開,我上面寫的代碼來自FORM2。 – Marcus 2010-11-21 01:20:58