更新mysql数据库(DDT-groupname)

时间:2015-10-10 16:51:17

标签: c# mysql visual-studio sql-update

MySqlConnection conn = new MySqlConnection("server=localhost;uid=root;" + "pwd=password;database=ddt_data");

conn.Open();
string command = "Update `fixture` SET `referee`=@referee, `ScoreA`=@ScoreA, `ScoreB`=@ScoreB, `Winner`=@Winner WHERE idfixture=" + Request.QueryString["idfixture"];
MySqlCommand update = new MySqlCommand(command, conn);

update.Parameters.AddWithValue("@referee", this.txtRef.Text);
update.Parameters.AddWithValue("@scorea", this.txtScoreA.Text);
update.Parameters.AddWithValue("@scoreb", this.txtScoreB.Text);
update.Parameters.AddWithValue("@winner", this.txtWinner.Text);

update.ExecuteNonQuery(); // use this if you don't need the DataReader
conn.Close();
conn.Dispose();        

1 个答案:

答案 0 :(得分:0)

        MySqlConnection conn = new MySqlConnection("server=localhost;uid=root;" + "pwd=password;database=ddt_data");
        conn.Open();
        try
        {

            string command = "Update fixture SET referee =@referee," + "ScoreA = @ScoreA, ScoreB = @ScoreB, Winner = @Winner " + "WHERE idfixture= " + Request.QueryString["idfixture"];
            MySqlCommand update = new MySqlCommand(command, conn);
            update.Parameters.AddWithValue("@referee", this.txtRef.Text);
            update.Parameters.AddWithValue("@scorea", this.txtScoreA.Text);
            update.Parameters.AddWithValue("@scoreb", this.txtScoreB.Text);
            update.Parameters.AddWithValue("@winner", this.txtWinner.Text);
            update.ExecuteNonQuery(); // use this if you don't need the DataReader
            conn.Close();
            conn.Dispose();
        }
        catch { }
    }