开发者社区> 问答> 正文

System.Data.SqlClient.SqlException”,但未在用户代码中处理附加信息

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

System.Data.dll中发生“ System.Data.SqlClient.SqlException”,但未在用户代码中处理附加信息:“,”附近的语法不正确

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();
       }

展开
收起
祖安文状元 2020-01-03 18:48:05 591 0
1 条回答
写回答
取消 提交回答
  • 更改此:

    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。代替逗号。

    2020-01-03 18:48:21
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载