当我尝试从asp.net中的Visual Studio C#将SQL Server数据更新为大写时,出现此错误: 'System.Data.SqlClient.SqlException'发生在System.Data.dll中,但
用户代码未处理附加信息:语法错误
在','附近 代码 答案 0 :(得分:2) 更改此: 到 用
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 个答案:
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
替换逗号。