I have a structure declared in a separate file. I need to fill it with data from one database and insert it into another, but the error with the types persists. I suspect that the syntax of the request with the parameters is not true.

string SQLrequest = @"SELECT id, guid, username, userblob FROM ""USERS"""; NpgsqlCommand command = new NpgsqlCommand(SQLrequest, conn); try { NpgsqlDataReader dr = command.ExecuteReader(); // here exception while (dr.Read()) { // UserData ud = new UserData(); ud.id = dr[0].ToString(); ud.guid = (dr[1].ToString()); ud.name = (dr[2].ToString()); ud.userblob = (byte[]) dr[3]; } dr.Dispose(); // releases conenction } 

It seems to be true, or am I mistaken about something?

  public void insertDataFromPGToSQLLite(UserData ud) { SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=" + config.SQLLitePath + ";Version=3;"); m_dbConnection.Open(); SQLiteCommand insertSQL = new SQLiteCommand("INSERT INTO test01.USERS id, guid, name, userblob) VALUES (?,?,?,?)", m_dbConnection); try { insertSQL.Parameters.Add(ud.id); insertSQL.Parameters.Add(ud.guid); insertSQL.Parameters.Add(ud.name); insertSQL.Parameters.Add(ud.userblob); Console.WriteLine("!!!"); insertSQL.ExecuteNonQuery(); Console.WriteLine("DONE"); } catch (Exception e) { Console.WriteLine(e.StackTrace); } finally { m_dbConnection.Close(); } } 

Query with Insert Parameters

    2 answers 2

    And as for me, the problem is in adding parameters, as directly and swears in the console.

    You need to write:

     insertSQL.Parameters.Add(new SQLiteParameter(....)); 

    And here, actually, the description .

    • for sure. Only link soon: devart.com/dotconnect/sqlite/docs/… - Igor
    • I agree, I just gave a description of the designers, I didn’t finish it ... - SlavonDT
    • I tried to do this: insertSQL.Parameters.Add(new SQLiteParameter(ud.userblob, DbType.Byte)); but I have the same byte[] array, and so the judge doesn’t suggest me - Dmitry Bubnenkov
    • one
      @Suliman SQLiteType.Blob - Igor 2:41 SQLiteType.Blob

    "INSERT INTO test01.USERS id, guid, name, userblob) VALUES (?,?,?,?)"

    Missing "(", opening list of fields.

    "INSERT INTO test01.USERS (id, guid, name, userblob) VALUES (?,?,?,?)"