Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. reader.Read() to string array

reader.Read() to string array

Scheduled Pinned Locked Moved Managed C++/CLI
c++databasesqlitedata-structureshelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thilek
    wrote on last edited by
    #1

    Hi guys, i am writing a program that get data from a sqlite database and add the records to a string array. But i not sure how to add to the string array. i search few ways on net and try out, but it didnt work. Below is my coding :

    string signature_array[100];
    int count =0;

    SQLiteConnection ^connection = gcnew SQLiteConnection("Data Source=test.db3;Pooling=True");
    connection->Open();
    SQLiteCommand ^cmd = gcnew SQLiteCommand(connection);
    SQLiteDataReader ^reader = cmd->ExecuteReader();

    while (reader->Read())
    {
    signature_array[count]=reader->GetString(2);
    count++;
    }
    reader->Close();

    kindly help me.. i am using visual C++ pro 2008... Thank you. Regards, Thilek ;)

    N 1 Reply Last reply
    0
    • T Thilek

      Hi guys, i am writing a program that get data from a sqlite database and add the records to a string array. But i not sure how to add to the string array. i search few ways on net and try out, but it didnt work. Below is my coding :

      string signature_array[100];
      int count =0;

      SQLiteConnection ^connection = gcnew SQLiteConnection("Data Source=test.db3;Pooling=True");
      connection->Open();
      SQLiteCommand ^cmd = gcnew SQLiteCommand(connection);
      SQLiteDataReader ^reader = cmd->ExecuteReader();

      while (reader->Read())
      {
      signature_array[count]=reader->GetString(2);
      count++;
      }
      reader->Close();

      kindly help me.. i am using visual C++ pro 2008... Thank you. Regards, Thilek ;)

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Thilek wrote:

      string signature_array[100];

      This is not a C++/CLI array. In C++/CLI, strings are written like String^. And array is created like

      array<String^>^ stringArray = gcnew array<String^>(arrayLength)

      In your case, a generic List(String^) will be appropriate.

      List<String^>^ stringList = gcnew List<String^>();
      SQLiteConnection ^connection = gcnew SQLiteConnection("Data Source=test.db3;Pooling=True");
      connection->Open();
      SQLiteCommand ^cmd = gcnew SQLiteCommand(connection);
      SQLiteDataReader ^reader = cmd->ExecuteReader();
      while (reader->Read())
      {
      stringList->Add(reader->GetString(2));
      }
      reader->Close();

      This will avoid maintaining a count variable explicitly. List is capable to expand and shrink whenever required. For SQLiteConnection and SQLiteCommand , you can use stack semantics which will ensure the objects are disposed once the scope ends. I can't see you are disposing them in your code. :)

      Navaneeth How to use google | Ask smart questions

      T 1 Reply Last reply
      0
      • N N a v a n e e t h

        Thilek wrote:

        string signature_array[100];

        This is not a C++/CLI array. In C++/CLI, strings are written like String^. And array is created like

        array<String^>^ stringArray = gcnew array<String^>(arrayLength)

        In your case, a generic List(String^) will be appropriate.

        List<String^>^ stringList = gcnew List<String^>();
        SQLiteConnection ^connection = gcnew SQLiteConnection("Data Source=test.db3;Pooling=True");
        connection->Open();
        SQLiteCommand ^cmd = gcnew SQLiteCommand(connection);
        SQLiteDataReader ^reader = cmd->ExecuteReader();
        while (reader->Read())
        {
        stringList->Add(reader->GetString(2));
        }
        reader->Close();

        This will avoid maintaining a count variable explicitly. List is capable to expand and shrink whenever required. For SQLiteConnection and SQLiteCommand , you can use stack semantics which will ensure the objects are disposed once the scope ends. I can't see you are disposing them in your code. :)

        Navaneeth How to use google | Ask smart questions

        T Offline
        T Offline
        Thilek
        wrote on last edited by
        #3

        i try using this and i got the following errors :-

        c:\documents and settings\thilek\desktop\sparta test\trial.cpp\Scanner.cpp(114) : error C2065: 'List' : undeclared identifier
        c:\documents and settings\thilek\desktop\sparta test\trial.cpp\Scanner.cpp(114) : error C2275: 'System::String' : illegal use of this type as an expression
        c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::String'
        c:\documents and settings\thilek\desktop\sparta test\trial.cpp\Scanner.cpp(114) : error C2059: syntax error : '>'
        c:\documents and settings\thilek\desktop\sparta test\trial.cpp\Scanner.cpp(143) : error C2065: 'stringList' : undeclared identifier
        c:\documents and settings\thilek\desktop\sparta test\trial.cpp\Scanner.cpp(143) : error C2227: left of '->Add' must point to class/struct/union/generic type
        type is ''unknown-type''
        Scanner.cpp
        .\Scanner.cpp(114) : error C2065: 'List' : undeclared identifier
        .\Scanner.cpp(114) : error C2275: 'System::String' : illegal use of this type as an expression
        c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::String'
        .\Scanner.cpp(114) : error C2059: syntax error : '>'
        .\Scanner.cpp(143) : error C2065: 'stringList' : undeclared identifier
        .\Scanner.cpp(143) : error C2227: left of '->Add' must point to class/struct/union/generic type
        type is ''unknown-type''

        N 1 Reply Last reply
        0
        • T Thilek

          i try using this and i got the following errors :-

          c:\documents and settings\thilek\desktop\sparta test\trial.cpp\Scanner.cpp(114) : error C2065: 'List' : undeclared identifier
          c:\documents and settings\thilek\desktop\sparta test\trial.cpp\Scanner.cpp(114) : error C2275: 'System::String' : illegal use of this type as an expression
          c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::String'
          c:\documents and settings\thilek\desktop\sparta test\trial.cpp\Scanner.cpp(114) : error C2059: syntax error : '>'
          c:\documents and settings\thilek\desktop\sparta test\trial.cpp\Scanner.cpp(143) : error C2065: 'stringList' : undeclared identifier
          c:\documents and settings\thilek\desktop\sparta test\trial.cpp\Scanner.cpp(143) : error C2227: left of '->Add' must point to class/struct/union/generic type
          type is ''unknown-type''
          Scanner.cpp
          .\Scanner.cpp(114) : error C2065: 'List' : undeclared identifier
          .\Scanner.cpp(114) : error C2275: 'System::String' : illegal use of this type as an expression
          c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::String'
          .\Scanner.cpp(114) : error C2059: syntax error : '>'
          .\Scanner.cpp(143) : error C2065: 'stringList' : undeclared identifier
          .\Scanner.cpp(143) : error C2227: left of '->Add' must point to class/struct/union/generic type
          type is ''unknown-type''

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          Thilek wrote:

          'List' : undeclared identifier

          Have you added _using namespace System::Collections::Generic_?

          Navaneeth How to use google | Ask smart questions

          T 1 Reply Last reply
          0
          • N N a v a n e e t h

            Thilek wrote:

            'List' : undeclared identifier

            Have you added _using namespace System::Collections::Generic_?

            Navaneeth How to use google | Ask smart questions

            T Offline
            T Offline
            Thilek
            wrote on last edited by
            #5

            thanks bro.. its working :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups