1
        using (MySqlCommand bb = new MySqlCommand("UPDATE  members SET  Begin = 1 WHERE id ='" + uid + "';"))
        {
            bb.Connection = con;
            con.Open();
            using (MySqlCommand fff = new MySqlCommand("UPDATE  members SET  b = 1 WHERE id ='" + uid + "';"))
            {
                fff.Connection = con;
            }
            this.Hide();
            Main main = new Main();
            main.Show();
        }

B と Begin の両方のテーブルを現在ログインしているユーザーに更新しようとしています (私の uid コマンド:

  using (MySqlCommand id = new MySqlCommand("SELECT id FROM members WHERE username='" + textBox1.Text + "';"))
                            {
                                id.Connection = con;
                                MySqlDataReader read3 = cmd.ExecuteReader();
                                read3.Dispose();
                                int idd = (int)id.ExecuteScalar();
                                uid = idd;
                                Begin.uid = idd;
                                MySqlDataReader read4 = id.ExecuteReader();
                                read4.Dispose();
                                id.Dispose();
                            }

理由はわかりませんが、データベースが更新されません。

4

2 に答える 2

0

まず第一に、ユーザーがパラメーター化したクエリを使用し、次にExecuteNonQuery()任意のSqlCommands.

using (MySqlCommand bb = new MySqlCommand("UPDATE  members SET  Begin = 1 WHERE id = @id;"))
{
    bb.Parameters.AddWithValue("@id", uid);
    bb.Connection = con;
    con.Open();

    bb.ExecuteNonQuery();

    using (MySqlCommand fff = new MySqlCommand("UPDATE  members SET  b = 1 WHERE id = @id;"))
    {
        fff.Parameters.AddWithValue("@id", uid);
        fff.Connection = con;

        fff.ExecuteNonQuery();
    }

    this.Hide();
    Main main = new Main();
    main.Show();
}
于 2013-07-01T13:11:19.273 に答える