Results 1 to 5 of 5

Thread: [RESOLVED] Need help with updating SQLite database

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    Resolved [RESOLVED] Need help with updating SQLite database

    Hello, I want to insert cell value to my database. Here's my code:

    VB.NET Code:
    1. private void UpdateMD5Record(string fn, string md5)
    2. {
    3.     m_dbConnection.Open();
    4.  
    5.     SQLiteCommand command = new SQLiteCommand("PRAGMA foreign_keys = ON", m_dbConnection);
    6.     command.ExecuteNonQuery();
    7.  
    8.     string sql = @"UPDATE 'tbl_programs' " +
    9.             @"SET('txt_md5' = :md5) " +
    10.             @"WHERE ('txt_programName' = :pn" +
    11.         @"); ";
    12.     command = new SQLiteCommand(sql, m_dbConnection);
    13.     command.Parameters.AddWithValue("md5", md5);
    14.     command.Parameters.AddWithValue("pn", fn);
    15.     command.ExecuteNonQuery();
    16.     m_dbConnection.Close();
    17. }

    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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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:
    1. string sql = "UPDATE 'tbl_programs'
    2.               SET 'txt_md5' = :md5
    3.               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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    Re: Need help with updating SQLite database

    Wow that works fine. Yes, I can see ":" prefix is working fine. Thanks a lot.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    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:
    1. private void UpdateMD5Record(string fc, string md5) // Full command, md5
    2. {
    3.     Console.WriteLine("fc = " + fc + "    md5 = " + md5);

    fc = msiexec -i "7z1604.msi" /qn md5 = 8cfd1629f23dfdad978349c93241ef6d

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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
  •  



Click Here to Expand Forum to Full Width