I create a structure. Then I fill it with creation and I want to transfer each element of this structure to another method and there already (in another DB) perform data insertion. Here is the code:

void selectDataForSync() //data from PG that whould be insert in SQLLITE { UserData ud; List<UserData> uds = new List<UserData>(); NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=" + config.PGLogin + ";" + "Password=" + config.PGPass + ";"); conn.Open(); string SQLrequest = @"SELECT guid, username, ""FL"", id, userblob FROM ""USERS"" WHERE ""FL""=10;"; NpgsqlCommand command = new NpgsqlCommand(SQLrequest, conn); try { NpgsqlDataReader dr = command.ExecuteReader(); // here exception while (dr.Read()) { // UserData ud = new UserData(); ud.id = Int32.Parse(dr[0].ToString()); ud.guid = (dr[1].ToString()); ud.name = (dr[2].ToString()); ud.userblob = (byte[])dr[3]; // uds.Add(ud); sqllite.insertDataFromPGToSQLLite(ud); } dr.Dispose(); // releases conenction } catch (Exception e) { Console.WriteLine(e.Message); } finally { conn.Close(); } } 

Persistently swears at the line: sqllite.insertDataFromPGToSQLLite(ud); Mol: argument type is not assignable to parameter type

The definition of the structure itself looks like this

On the SQLLite side, the code is:

  public struct UserData { public int id; public string guid; public string name; public byte[] userblob; }; public void insertDataFromPGToSQLLite(UserData ud) { } 
  • it is written: different types. Use DBSync.DB.SQLLite.UserData ud; - Igor
  • Why is that different? UserData ud; declared type sqllite.insertDataFromPGToSQLLite(ud); I transferred the data to the structure in the SQLLite part added the same as here. Look at the post, I updated it. - Dmitry Bubnenkov
  • UserData type UserData defined in two places: DBSync.Postgres and DBSync.DB.SQLLite . You declared a variable of type DBSync.Postgres.UserData , and the sqllite.insertDataFromPGToSQLLite method needs DBSync.DB.SQLLite.UserData . - Igor
  • Could you show me how to declare? This data has the same structure. - Dmitry Bubnenkov

1 answer 1

UserData type UserData defined in two places: DBSync.Postgres and DBSync.DB.SQLLite . You declared a variable of type DBSync.Postgres.UserData , and the sqllite.insertDataFromPGToSQLLite method needs DBSync.DB.SQLLite.UserData .

Leave only one definition of type UserData and use it everywhere.

This data has the same structure.

It does not matter. For the compiler, these are two completely different types.

  • So, is it possible to declare a UserData declaration in a separate class and do import everywhere? Well, that he and there and there was visible. - Dmitry Bubnenkov
  • In a separate file or even in a separate project (Class Library), but at this stage it may be a brute force. - Igor
  • So? img.ctrlv.in/img/16/04/25/571e2a574d37c.png And further using UserDataStruct ? - Dmitry Bubnenkov
  • yes, if this type is in the namespace UserDataStruct - Igor