dionisio_79
asked on
I've got the following exception when I try to run the code below:
Hi Experts,
I've got the following exception when I try to run the code below:
ExecuteReader: CommandText property has not been initialized
The first time it runs without errors, the exception occours when I recall it.
conn = new SqlConnection(Constants.Co nnectionDb Supporto);
string queryString = "SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='" + nomeTab + "'";
SqlCommand sqlcmd = new SqlCommand(queryString, conn);
if (conn.State == ConnectionState.Closed)
conn.Open();
sqlcmd.CommandText = queryString;
sqlDr = sqlcmd.ExecuteReader();
while (sqlDr.Read())
{
... }
sqlDr.Close();
I've got the following exception when I try to run the code below:
ExecuteReader: CommandText property has not been initialized
The first time it runs without errors, the exception occours when I recall it.
conn = new SqlConnection(Constants.Co
string queryString = "SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE FROM INFORMATION_SCHEMA.COLUMNS
SqlCommand sqlcmd = new SqlCommand(queryString, conn);
if (conn.State == ConnectionState.Closed)
conn.Open();
sqlcmd.CommandText = queryString;
sqlDr = sqlcmd.ExecuteReader();
while (sqlDr.Read())
{
... }
sqlDr.Close();
Hello
Try this instead:
SqlCommand sqlcmd = conn.CreateCommand();
:-)
Try this instead:
SqlCommand sqlcmd = conn.CreateCommand();
:-)
ASKER
I've tryed with the createcommand method but the result is still the same
The method is called in the ExportForm_load method which is the event handler for the form load event.
this.Load += new EventHandler(ExportForm_Lo ad);
the second time, when I press a button, I recall the load method:
this.ExportForm_Load(this, new EventArgs());
The method is called in the ExportForm_load method which is the event handler for the form load event.
this.Load += new EventHandler(ExportForm_Lo
the second time, when I press a button, I recall the load method:
this.ExportForm_Load(this,
BAD.
Have a function that performs this code.
Call the function from the Load event and from the button event.
Have a function that performs this code.
Call the function from the Load event and from the button event.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've changed the code as you suggested but I've got the same result
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window