data set using the wizard RRS feed

  • Question

  • DS2 ds = new DS2();
    mytableTableAdapter da1 = new DS2TableAdapters.mytableTableAdapter();
    lable2.Text = ds.Tables[0].Rows[0].ItemArray[0].ToString();
    after compiling this code this message appear
    System.InvalidOperationException was unhandled by user code
       Message=The SelectCommand property has not been initialized before calling 'Fill'.
            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 MySqlWeb._Default.ld_Click(Object sender, EventArgs e) in C:\Users\Ahmad\documents\visual studio 2010\Projects\MySqlWeb\MySqlWeb\Default.aspx.cs:line 39
            at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
            at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
            at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
            at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
            at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
            at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    Tuesday, June 7, 2011 10:25 AM


  • Hello prutal,

    Thanks for your post.

    According to the error message, I didn't find the SelectCommand. Normally, if we use Typed DataSet and TableAdapter, we don't need initialize the selectcommand in the code. However, this kind of error happened in your scenario, basically, please try this way to initialize by yourself:


    mytableTableAdapter da1 = new DS2TableAdapters.mytableTableAdapter();

    da1.SelectCommand = cmd;  //cmd is your  the command with adapter you intialized before this.

    However, I think there's another reason causing this error, could you please show us more details about your scenario? Such as your steps of coding.

    I hope this can help you.


    Good day,

    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 9, 2011 9:46 AM