I have been staring at this code too long. This block keeps throwing an exception which says :
{System.Data.SQLite.SQLiteException (0x80004005): SQL logic error or missing database
near ",": syntax error
That sounds like it could be the forming of my SQL, but I don't see it.
I know the process of creating and filling the parameters is correct. It works in other places of the same application. The SQL looks good when I check it as a string, but I cannot check it just before it goes to the SQLite engine.
Research has confirmed my process, but I am missing something or a typo is just hiding from me. Can you please take a look and see if the error stands out to you? Is there a better way to go about this?
Code
public static int updatePartner( Partner updatedPartner, Partner oldPartner)
{
int result = 0;
SQLiteConnection connection = GroomwatchDB.GetConnection();
string sqlStatement = "UPDATE partners SET [last_name] = @lastName, [first_name] = @firstName, "
+ "[pay_rate] = @payRate, [active] = @uactive "
+ "WHERE [partner_code] = @oldPartnerCode, [last_name] = @oldLastName, [first_name] = @oldFirstName "
+ "[pay_rate] = @oldPayRate, [active] = @oldActive";
MessageBox.Show(sqlStatement);
SQLiteCommand command = new SQLiteCommand(sqlStatement, connection);
command.Parameters.Add(new SQLiteParameter("@lastName"));
command.Parameters.Add(new SQLiteParameter("@firstName"));
command.Parameters.Add(new SQLiteParameter("@payRate"));
command.Parameters.Add(new SQLiteParameter("@uactive"));
command.Parameters.Add(new SQLiteParameter("@oldPartnerCode"));
command.Parameters.Add(new SQLiteParameter("@oldLastName"));
command.Parameters.Add(new SQLiteParameter("@oldFirstName"));
command.Parameters.Add(new SQLiteParameter("@oldPayRate"));
command.Parameters.Add(new SQLiteParameter("@oldActive"));
command.Parameters["@lastName"].Value = updatedPartner.Last_name;
command.Parameters["@firstName"].Value = updatedPartner.First_name;
command.Parameters["@payRate"].Value = updatedPartner.Pay_rate;
command.Parameters["@uactive"].Value = updatedPartner.Active;
command.Parameters["@oldPartnerCode"].Value = oldPartner.Code;
command.Parameters["@oldLastName"].Value = oldPartner.Last_name;
command.Parameters["@oldFirstName"].Value = oldPartner.First_name;
command.Parameters["@oldPayRate"].Value = oldPartner.Pay_rate;
command.Parameters["@oldActive"].Value = oldPartner.Active;
try
{
connection.Open();
result = command.ExecuteNonQuery();
}
catch (SQLiteException ex)
{
throw ex;
}
finally
{
connection.Close();
}
return result;
}
Aucun commentaire:
Enregistrer un commentaire