当我尝试从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();
}
更改此:
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。代替逗号。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。