-
Aug 13th, 2017, 10:05 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Need help with updating SQLite database
Hello, I want to insert cell value to my database. Here's my code:
VB.NET Code:
private void UpdateMD5Record(string fn, string md5)
{
m_dbConnection.Open();
SQLiteCommand command = new SQLiteCommand("PRAGMA foreign_keys = ON", m_dbConnection);
command.ExecuteNonQuery();
string sql = @"UPDATE 'tbl_programs' " +
@"SET('txt_md5' = :md5) " +
@"WHERE ('txt_programName' = :pn" +
@"); ";
command = new SQLiteCommand(sql, m_dbConnection);
command.Parameters.AddWithValue("md5", md5);
command.Parameters.AddWithValue("pn", fn);
command.ExecuteNonQuery();
m_dbConnection.Close();
}
However I'm getting this error:
An unhandled exception of type 'System.Data.SQLite.SQLiteException' occurred in System.Data.SQLite.dll
Additional information: SQL logic error or missing database
near "=": syntax error
Can anyone help me?
-
Aug 13th, 2017, 10:40 AM
#2
Re: Need help with updating SQLite database
I'd suggest that you remove those parentheses. I'm not 100% sure but I suspect that at least one set of them is illegal and possibly both. They certainly don't add anything useful to your SQL code.
By the way, the @ symbols on your String literals are pointless. There's no escaped characters in any of them so using a verbatim String literal has no effect. Also, I'd suggest that you are making your code harder to read by concatenating Strings in that way. For such a short bit of SQL code, why not just put it al on one line? If you do want to break it up, C# supports multiline literals so you don't need to concatenate:
csharp Code:
string sql = "UPDATE 'tbl_programs'
SET 'txt_md5' = :md5
WHERE 'txt_programName' = :pn";
While I think of it, are you sure that SQLite supports ":" as a parameter prefix and then omitting it when adding the parameter? I don't use SQLite so I don't know but I've only seen "@" used with that provider and it has been used in both the SQL code and when adding the parameter.
-
Aug 13th, 2017, 10:56 AM
#3
Thread Starter
Addicted Member
Re: Need help with updating SQLite database
Wow that works fine. Yes, I can see ":" prefix is working fine. Thanks a lot.
-
Aug 13th, 2017, 01:54 PM
#4
Thread Starter
Addicted Member
Re: Need help with updating SQLite database
Hi, now I have another problem. I don't get any errors but the database isn't updating. Here's one of the outputs of
VB.NET Code:
private void UpdateMD5Record(string fc, string md5) // Full command, md5 { Console.WriteLine("fc = " + fc + " md5 = " + md5);
fc = msiexec -i "7z1604.msi" /qn md5 = 8cfd1629f23dfdad978349c93241ef6d
-
Aug 13th, 2017, 07:43 PM
#5
Re: Need help with updating SQLite database
If the original issue has been resolved then please mark this thread Resolved using the Thread Tools menu. If you have a new issue, please start a new thread with a title that summarises that issue specifically.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|