使用C#更新SQL表

问题描述

我正在尝试更新Episode表中的EpisodeId:117,它成功执行,但是当我检查该表时,它没有更新。 int集ID = 117;

int seriesNumber = 9;
int episodeNumber = 13;
string episodeType = "abnormal episode";
string title = "Reconsideration";
string notes = "recuring behaviour";

//connectionString
 
string connectionString = "data source=LAPTOP-VLO4EFFQ\\MSSQLSERVER01; database=DoctorWho; integrated Security=True;";

//connection using
using (SqlConnection conn = new SqlConnection(connectionString))
{
    
    conn.Open();
    Console.WriteLine("Connection sucessfull");

    string query = "UPDATE tblEpisode " +
        "(SeriesNumber,EpisodeNumber,EpisodeType,Title,Notes)" +
        "(SET SeriesNumber=@SeriesNumber,EpisodeNumber=@EpisodeNumber,EpisodeType=@EpisodeType,Title=@Title,Notes=@Notes)" +
        "(WHERE EpisodeId=@EpisodeId)";

    using (SqlCommand command = new SqlCommand(query,conn))
    {
        //updating data in the sql table with the initial variables  
        command.Parameters.Add("@EpisodeId",System.Data.SqlDbType.Int).Value = episodeId;
        command.Parameters.Add("@SeriesNumber",System.Data.SqlDbType.Int).Value = seriesNumber;
        command.Parameters.Add("@EpisodeNumber",System.Data.SqlDbType.Int).Value = episodeNumber;
        command.Parameters.Add("@EpisodeType",System.Data.SqlDbType.NVarChar).Value = episodeType;
        command.Parameters.Add("@Title",System.Data.SqlDbType.NVarChar).Value = title;
        command.Parameters.Add("@Notes",System.Data.SqlDbType.NVarChar).Value = notes;

    }


    conn.Close();
    Console.WriteLine("connection is closed!!");
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)