ExecuteReader() or MySqlDataTable
Posted: Mon 27 Dec 2004 17:28
hi. I try to select a colomn of names and use them to create new tables. I first try to use the Read method to put this names in an array so that i may use them afterwards to create the tables :
String* nomTitre[]=0;
String *q;
q="SELECT CQG from titres";
MySqlConnection * cntd= new MySqlConnection("User=root;Host=localhost;Port=3306;Database=base Weekly");
cntd->Open();
MySqlCommand *myCommand = new MySqlCommand(q,cntd);
MySqlDataReader *myReader=myCommand->ExecuteReader();
int i=0;
while (myReader->Read()){
nomTitre=myReader->GetString(0);
}
myReader->Close;
while (nomTitre){
q=String::Format(S"CREATE TABLE {0} (date DATE, open FLOAT, high FLOAT,low FLOAT,close FLOAT)",nomTitre);
myCommand->CommandText =q;
myCommand->ExecuteNonQuery();
i++;
}
but then i have a " non handled System.NullReferenceException", "the object reference is not defined to an instance obect" with the line
nomTitre=myReader->GetString(0);
...
Then I tried with MySqlDataTable :
q="SELECT code from titres";
MySqlDataTable *myDataTable = new MySqlDataTable(q,"User=root;Host=localhost;Port=3306;Database=base Weekly");
myDataTable->Active = true;
foreach(DataRow myRow in myDataTable->Row)
{
foreach(DataColumn myCol in myDataTable->Columns)
{
q=String::Format(S"CREATE TABLE {0} (date DATE, open FLOAT, high FLOAT,low FLOAT,close FLOAT)",myRow[myCol]);
myCommand->CommandText =q;
myCommand->ExecuteNonQuery();
}
}
myDataTable->Active =false;
but then i hace a problem with the type DataRow : " uncorrect use of this type as an expression"...
Can you help me on either of the solutions i tried ?
String* nomTitre[]=0;
String *q;
q="SELECT CQG from titres";
MySqlConnection * cntd= new MySqlConnection("User=root;Host=localhost;Port=3306;Database=base Weekly");
cntd->Open();
MySqlCommand *myCommand = new MySqlCommand(q,cntd);
MySqlDataReader *myReader=myCommand->ExecuteReader();
int i=0;
while (myReader->Read()){
nomTitre=myReader->GetString(0);
}
myReader->Close;
while (nomTitre){
q=String::Format(S"CREATE TABLE {0} (date DATE, open FLOAT, high FLOAT,low FLOAT,close FLOAT)",nomTitre);
myCommand->CommandText =q;
myCommand->ExecuteNonQuery();
i++;
}
but then i have a " non handled System.NullReferenceException", "the object reference is not defined to an instance obect" with the line
nomTitre=myReader->GetString(0);
...
Then I tried with MySqlDataTable :
q="SELECT code from titres";
MySqlDataTable *myDataTable = new MySqlDataTable(q,"User=root;Host=localhost;Port=3306;Database=base Weekly");
myDataTable->Active = true;
foreach(DataRow myRow in myDataTable->Row)
{
foreach(DataColumn myCol in myDataTable->Columns)
{
q=String::Format(S"CREATE TABLE {0} (date DATE, open FLOAT, high FLOAT,low FLOAT,close FLOAT)",myRow[myCol]);
myCommand->CommandText =q;
myCommand->ExecuteNonQuery();
}
}
myDataTable->Active =false;
but then i hace a problem with the type DataRow : " uncorrect use of this type as an expression"...
Can you help me on either of the solutions i tried ?