2

クエリを送信すると、例外はスローされず、データベースに書き込まれますが、必要なものではありません。何らかの理由で、クエリに最初に伝えたもの以外には何も触れず、それを 0 に設定します。

これが私のコードです:

    public static int UpdateTagDefinition(Dictionary<string, object> sqlQueryParams)
    {
        MySqlCommand query = new MySqlCommand();
        query.CommandText = "UPDATE `windows_dev` SET `name` = @name AND `desc_short` = @desc_short AND `desc_long` = @desc_long AND `tags` = @tags AND `image_title` = @image_title AND `images` = @images AND `release_date` = @release_date AND `update_date` = @update_date AND `is_on_sourcecontrol` = @is_on_sourcecontrol AND `sourcecontrol_type` = @sourcecontrol_type AND `sourcecontrol_uri` = @sourcecontrol_uri AND `download_uri` = @download_uri AND `project_uri` = @project_uri AND `source_uri` = @source_uri AND `is_public` = @is_public WHERE `DID` = @did;";
        query.Parameters.Clear();
        foreach(var sqlParam in sqlQueryParams)
        {
            query.Parameters.AddWithValue("@" + sqlParam.Key.ToString(), sqlParam.Value);
        }

        return Connector.RunSQLUpdateQuery(query);
    }

    public static int RunSQLUpdateQuery(MySqlCommand query)
    {
        try
        {
            MySqlConnection cnx = new MySqlConnection(ConfigurationManager.ConnectionStrings["******"].ConnectionString);

            // Connect to News Database and get recent article
            query.Connection = cnx;
            cnx.Open();
            MySqlDataReader Reader;
            Reader = query.ExecuteReader();
            cnx.Close();

            return 1;
        }
        catch
        {
            return 2;
        }
    }

そして、SQL パラメータを設定した場所。

            Dictionary<string, object> sqlQueryParams = new Dictionary<string, object>();
            sqlQueryParams.Add("name", Request.Form["name"]);
            sqlQueryParams.Add("desc_short", Request.Form["desc_short"]);
            sqlQueryParams.Add("desc_long", Request.Form["desc_long"]);
            sqlQueryParams.Add("tags", TagDefinitions.TagDefinitionsToSQL(TagDefinitions.GetTagDefinitionIdentsFromList((List<string>)JsonConvert.DeserializeObject(Request.Form["tags"], typeof(List<string>)))));
            sqlQueryParams.Add("image_title", Request.Form["image_title"]);
            sqlQueryParams.Add("images", Request.Form["images"]);
            sqlQueryParams.Add("release_date", Request.Form["release_date"]);
            sqlQueryParams.Add("update_date", Request.Form["update_date"]);
            sqlQueryParams.Add("is_on_sourcecontrol", Request.Form["is_on_sourcecontrol"]);
            sqlQueryParams.Add("sourcecontrol_type", Request.Form["sourcecontrol_type"]);
            sqlQueryParams.Add("sourcecontrol_uri", Request.Form["sourcecontrol_uri"]);
            sqlQueryParams.Add("download_uri", Request.Form["download_uri"]);
            sqlQueryParams.Add("project_uri", Request.Form["project_uri"]);
            sqlQueryParams.Add("source_uri", Request.Form["source_uri"]);
            sqlQueryParams.Add("is_public", Request.Form["is_public"]);
            sqlQueryParams.Add("did", int.Parse(Request.Form["did"]));
4

1 に答える 1

8

複数の列を更新する場合は、COMMA代わりにを使用しますAND

query.CommandText = @"UPDATE `windows_dev` 
                      SET    `name` = @name, 
                             `desc_short` = @desc_short, 
                             ... other columns .....
                             `is_public` = @is_public 
                      WHERE `DID` = @did"; 
于 2012-12-25T12:46:36.363 に答える