in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

data type mismatch issue in a parametrized insert

Last post 02-12-2010 10:23 PM by pentium10. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 02-12-2010 10:37 AM

    data type mismatch issue in a parametrized insert

    cmd2.CommandText = "select * from " + TableName;
                        reader = cmd2.ExecuteReader();
                        if (reader != null)
                        {
    
                            String s = "".PadLeft(reader.FieldCount - 1, 'X').Replace("X", "?,") + "?";
                            cmd.CommandText = String.Format("{0} into {1} values ({2})", insertorreplace, TableName, s);
    
                            StringBuilder sb = new StringBuilder();
                            while (reader.Read())
                            {
                                int i = 0;
    
                                for (i = 0; i 
    Filed under:
  • 02-12-2010 11:00 AM In reply to

    Re: data type issue in a parametrized insert

    huh?

     

  • 02-12-2010 11:07 AM In reply to

    Re: data type issue in a parametrized insert

    post is there, just is not visible what to use to format properly? and I can't type in new line, what is wrong with this forum?

    Please help. If I edit the topic the code is visible well.
  • 02-12-2010 3:53 PM In reply to

    Re: data type issue in a parametrized insert

    The problem isn't the formatting ... it's that I haven't the foggiest what this code is supposed to do.  Can't you just show us the actual generated CommandText?

  • 02-12-2010 10:23 PM In reply to

    Re: data type issue in a parametrized insert

    In my first post only the first part of my code is visible.
    When I edit the post, in the edit window all code is visible.

    I have a table, I read out all values from it by a select *.
    Then for each of the fields I generate a parameterized query based on the reader.FieldCount eg: if fieldcount is 4, it will be " insert into table values (?,?,?,?)"

    then I use cmd.Parameters.AddWithValue(null,reader[i].ToString()); to replace these wildcards.
    Here is a link to a more readable query: http://stackoverflow.com/questions/2253830/datatype-mismatch-issue-in-a-parametrized-insert-query

    Using a insert into select from statement I get malformed database error, as I have to attach a new SQLite database, and it turns out it doesn't work as supposed to. Removing .ToString() doesn't help, as for example non-null columns needs to have empty value, and the provider sends null for it. SQLite doesn't force type, but I think the provider forces it.
Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems