reader.Read() to string array
-
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 ;)
-
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 ;)
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 likearray<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
andSQLiteCommand
, 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
-
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 likearray<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
andSQLiteCommand
, 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
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'' -
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''Thilek wrote:
'List' : undeclared identifier
Have you added
_using namespace System::Collections::Generic_
?Navaneeth How to use google | Ask smart questions
-
Thilek wrote:
'List' : undeclared identifier
Have you added
_using namespace System::Collections::Generic_
?Navaneeth How to use google | Ask smart questions