4Manuals

  • PDF Cloud HOME

'System.Data.SqlClient.SqlException'发生在System.Data.dll中,但未在用户代码中处理其他信息:',' Download

    获取Hough线的交点OpenCV C ++ 如何将字符串“ text1”设置为包含项目text1,text2,test3的组合框的选定项目? 为什么System.Net.Mail.MailAddress构造函数在域部分中解析带有斜杠“ /”的电子邮件? Android 10,API29:在应用程序文件夹中使用C ++库编写文件会使应用程序崩溃 Unity-LineRenderer没有出现在版本(2D)上 按下按钮后,电话中未显示通知 ASP.net,使用WebConfig httpErrors重定向到区域内的控制器不起作用 获取会议室详细信息 我们如何将参数Line转换为Station? 网络核心:查找实体框架核心的主键和反射

当我尝试从asp.net中的Visual Studio C#将SQL Server数据更新为大写时,出现此错误:

  

'System.Data.SqlClient.SqlException'发生在System.Data.dll中,但   用户代码未处理附加信息:语法错误   在','附近

代码

        String applicantSql = "SELECT applicantId, fullName, idNumber, idType, nationality, race, gender FROM applicant";
        SqlCommand cmd = new SqlCommand(applicantSql, connection);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        //fill the datatable with data
        da.Fill(dt);
        // Decrypt / Encrypt and Convert all Data to Uppercase
        foreach (DataRow dr in dt.Rows)
        {
            string idNumber = dr["idNumber"].ToString();
            string dcIdNumber = c.decryptInfo(idNumber).ToUpper();
            oupdatedIdNumber = dr["idNumber"].ToString();
            oupdatedFullName = dr["fullName"].ToString();
            oupdatedIdType = dr["idType"].ToString();
            oupdatedNationality = dr["nationality"].ToString();
            oupdatedRace = dr["race"].ToString();
            oupdatedGender = dr["gender"].ToString();
            updatedIdNumber = c.encryptInfo(dcIdNumber);
            updatedFullName = dr["fullName"].ToString().ToUpper();
            updatedIdType = dr["idType"].ToString().ToUpper();
            updatedNationality = dr["nationality"].ToString().ToUpper();
            updatedRace = dr["race"].ToString().ToUpper();
            updatedGender = dr["gender"].ToString().ToUpper();
            // Update applicant Table with latest data
            string updateApplicantSql = "UPDATE applicant SET idNumber = @idNumber, fullName = @fullName, idType = @idType, nationality = @nationality, race = @race, gender = @gender";
            updateApplicantSql += " WHERE idNumber = @oidNumber AND fullName = @ofullName AND idType = @oidType AND nationality = @onationality, race = @orace, gender = @ogender";
            SqlCommand cmdUpdateApplicant = new SqlCommand(updateApplicantSql, connection);
            connection.Open();
           cmdUpdateApplicant.Parameters.AddWithValue("@idNumber", updatedIdNumber);
            cmdUpdateApplicant.Parameters.AddWithValue("@fullName", updatedFullName);
            cmdUpdateApplicant.Parameters.AddWithValue("@idType", updatedIdType);
            cmdUpdateApplicant.Parameters.AddWithValue("@nationality", updatedNationality);
            cmdUpdateApplicant.Parameters.AddWithValue("@race", updatedRace);
            cmdUpdateApplicant.Parameters.AddWithValue("@gender", updatedGender);
            cmdUpdateApplicant.Parameters.AddWithValue("@oidNumber", oupdatedIdNumber);
            cmdUpdateApplicant.Parameters.AddWithValue("@ofullName", oupdatedFullName);
            cmdUpdateApplicant.Parameters.AddWithValue("@oidType", oupdatedIdType);
            cmdUpdateApplicant.Parameters.AddWithValue("@onationality", oupdatedNationality);
            cmdUpdateApplicant.Parameters.AddWithValue("@orace", oupdatedRace);
            cmdUpdateApplicant.Parameters.AddWithValue("@ogender", oupdatedGender);
            cmdUpdateApplicant.ExecuteNonQuery();
            connection.Close();
        }

1 个答案:

答案 0 :(得分:2)

更改此:

updateApplicantSql += " WHERE idNumber = @oidNumber AND fullName = @ofullName AND idType = @oidType AND nationality = @onationality, race = @orace, gender = @ogender";

到

updateApplicantSql += " WHERE idNumber = @oidNumber AND fullName = @ofullName AND idType = @oidType AND nationality = @onationality and race = @orace and gender = @ogender";

用and替换逗号。



Similar searches
    Samsung RB216AB Refrigerator User Manual 在窗口内创建菜单 寻找在Android手机上允许或阻止wifi网络的方法 垃圾不断插入IIS反向代理URL 我可以转换列表中数据帧的每个唯一ID吗?