none
ExecuteReader: CommandText property has not been initialized

    Question

  • Hi, im getting this error:

    ExecuteReader: CommandText property has not been initialized

     

    I think my coding of the DataAdapter is wrong somewhere, but I cant see it...can anybody help me out..thanks


    the code:

     

    private void IndividualResponseSQ_1()

                {

                      //query for SQ_1 response data

                     

                      SqlDataAdapter myAdapter = new SqlDataAdapter(sql, myConnection);

                      DataSet dsResults = new DataSet();

                      dsResults.Clear();

                      myAdapter.Fill(dsResults);

                      //set datasource

                      dgResults.DataSource = dsResults.Tables[0];

                      //bind table to datagrid

                      dgResults.DataBind();

                     

                     

                      sql =       "SELECT LOII.CRS_ID, LOII.EUS_ID, ";

                      sql +=            "LOII.ITM_ID, IA.IAT_DATA, ";

                      sql +=            "LOII.LII_RESPONSE_DATA, LOI.LOI_START_DATE, ";

                      sql +=            "LOI.LOI_END_DATE ";

                      sql +=            "FROM LEARNING_OBJECT_INSTANCE_ITEMS LOII";

                      sql +=            "INNER JOIN ITEM_ATTRIBUTES IA ON LOII.ITM_ID = IA.ITM_ID";

                      sql +=            "AND LOII.ITM_SEQ_NO = IA.ITM_SEQ_NO";

                      sql +=            "INNER JOIN END_USERS EU ON LOII.EUS_ID = EU.EUS_ID";

                      sql +=            "INNER JOIN LEARNING_OBJECT_INSTANCES LOI";

                      sql +=            "ON LOII.CRS_ID = LOI.CRS_ID";

                      sql +=            "AND LOII.CCP_ID = LOI.CCP_ID";

                      sql +=            "AND LOII.LOB_ID = LOI.LOB_ID";

                      sql +=            "AND LOII.EUS_ID = LOI.EUS_ID";

                      sql +=            "AND LOII.LOI_ID = LOI.LOI_ID";

                      sql +=            "WHERE LOII.LOB_ID = 'SURVEY_DEMO'";

                      sql +=            "AND LOII.ITM_ID = 'SQ_1'";

                      //RunReport(sql);

                }

    Wednesday, May 23, 2007 10:56 AM

Answers

  • Your passing an empty string o the datadapter. Create the sql string before passing the variable.

    private void IndividualResponseSQ_1()

                {

                      //query for SQ_1 response data

                     

                      sql =       "SELECT LOII.CRS_ID, LOII.EUS_ID, ";

                      sql +=            "LOII.ITM_ID, IA.IAT_DATA, ";

                      sql +=            "LOII.LII_RESPONSE_DATA, LOI.LOI_START_DATE, ";

                      sql +=            "LOI.LOI_END_DATE ";

                      sql +=            "FROM LEARNING_OBJECT_INSTANCE_ITEMS LOII";

                      sql +=            "INNER JOIN ITEM_ATTRIBUTES IA ON LOII.ITM_ID = IA.ITM_ID";

                      sql +=            "AND LOII.ITM_SEQ_NO = IA.ITM_SEQ_NO";

                      sql +=            "INNER JOIN END_USERS EU ON LOII.EUS_ID = EU.EUS_ID";

                      sql +=            "INNER JOIN LEARNING_OBJECT_INSTANCES LOI";

                      sql +=            "ON LOII.CRS_ID = LOI.CRS_ID";

                      sql +=            "AND LOII.CCP_ID = LOI.CCP_ID";

                      sql +=            "AND LOII.LOB_ID = LOI.LOB_ID";

                      sql +=            "AND LOII.EUS_ID = LOI.EUS_ID";

                      sql +=            "AND LOII.LOI_ID = LOI.LOI_ID";

                      sql +=            "WHERE LOII.LOB_ID = 'SURVEY_DEMO'";

                      sql +=            "AND LOII.ITM_ID = 'SQ_1'";

                      //RunReport(sql);


                      SqlDataAdapter myAdapter = new SqlDataAdapter(sql, myConnection);

                      DataSet dsResults = new DataSet();

                      dsResults.Clear();

                      myAdapter.Fill(dsResults);

                      //set datasource

                      dgResults.DataSource = dsResults.Tables[0];

                      //bind table to datagrid

                      dgResults.DataBind();

                     

                     


                }


    Wednesday, May 23, 2007 12:01 PM

All replies

  • Your passing an empty string o the datadapter. Create the sql string before passing the variable.

    private void IndividualResponseSQ_1()

                {

                      //query for SQ_1 response data

                     

                      sql =       "SELECT LOII.CRS_ID, LOII.EUS_ID, ";

                      sql +=            "LOII.ITM_ID, IA.IAT_DATA, ";

                      sql +=            "LOII.LII_RESPONSE_DATA, LOI.LOI_START_DATE, ";

                      sql +=            "LOI.LOI_END_DATE ";

                      sql +=            "FROM LEARNING_OBJECT_INSTANCE_ITEMS LOII";

                      sql +=            "INNER JOIN ITEM_ATTRIBUTES IA ON LOII.ITM_ID = IA.ITM_ID";

                      sql +=            "AND LOII.ITM_SEQ_NO = IA.ITM_SEQ_NO";

                      sql +=            "INNER JOIN END_USERS EU ON LOII.EUS_ID = EU.EUS_ID";

                      sql +=            "INNER JOIN LEARNING_OBJECT_INSTANCES LOI";

                      sql +=            "ON LOII.CRS_ID = LOI.CRS_ID";

                      sql +=            "AND LOII.CCP_ID = LOI.CCP_ID";

                      sql +=            "AND LOII.LOB_ID = LOI.LOB_ID";

                      sql +=            "AND LOII.EUS_ID = LOI.EUS_ID";

                      sql +=            "AND LOII.LOI_ID = LOI.LOI_ID";

                      sql +=            "WHERE LOII.LOB_ID = 'SURVEY_DEMO'";

                      sql +=            "AND LOII.ITM_ID = 'SQ_1'";

                      //RunReport(sql);


                      SqlDataAdapter myAdapter = new SqlDataAdapter(sql, myConnection);

                      DataSet dsResults = new DataSet();

                      dsResults.Clear();

                      myAdapter.Fill(dsResults);

                      //set datasource

                      dgResults.DataSource = dsResults.Tables[0];

                      //bind table to datagrid

                      dgResults.DataBind();

                     

                     


                }


    Wednesday, May 23, 2007 12:01 PM
  • Thanks, I didnt see that.

     

    much appreciated.

    Wednesday, May 23, 2007 12:16 PM
  • Hi,

    I am having similar problem with folllowing code, here I am setting sqlPartnerPorfolioQuery before passing it to SQLDataAdapter

     SqlConnection conn = new SqlConnection(base._SourceDataConnectionString);
    
          SqlDataAdapter adapter = new SqlDataAdapter(_sqlPartnerPorfolioQuery, conn);
    
          DataSet dsCRM = new DataSet();
    
          adapter.Fill(dsCRM);
    
          return dsCRM;
    

    The error that I get is

    System.InvalidOperationException: ExecuteReader: CommandText property has not been initialized
    at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
    at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
    at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
    at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
    at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
    at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
    at PMF_Partner_Sync.PartnerTeam.GetCRMPartnerPortfolioFromSource()
    at PMF_Partner_Sync.PartnerTeam.ImportPartnerTeamMembers()
    at PMF_Partner_Sync.Workflow.PartnerPortfolioSync.Execute(CodeActivityContext executionContext)
    ExecuteReader: CommandText property has not been initialized
    

    I am not able to find cause for this error

     


    makeer
    Saturday, February 26, 2011 7:18 PM
  • Not sure if it is the case in your instance, but for me, it was because my generated SQL statement was empty.
    I had the following code:

     

    Dim sSQL as string = ""
    if rows.count > 0
        sSQL = "SELECT * FROM someTable Where "
        for i = 0 to rows.count - 1
            sSQL &= " {condition} "
        next
    end if

     

    Because rows.count WAS in fact 0, sSQL was never set to anything and that cause the (slightly misleading) error message.

    • Edited by JP Strauss Thursday, October 06, 2011 1:09 PM
    Thursday, October 06, 2011 1:08 PM