The SelectCommand property has not been initialized before calling 'Fill'

被刻印的时光 ゝ 提交于 2019-12-13 00:00:59

问题


The SelectCommand property has not been initialized before calling 'Fill'

I am getting this error when running StoredProcedure.ExecuteDataSet();

 DataSet ds= new DataSet();
        SqlDataAdapter ada = new SqlDataAdapter();
        try
        {
            ada.Fill(ds);
        }
        catch { }

回答1:


I was able to fix this by adding the following code:

[162] DbDataAdapter da = Factory.CreateDataAdapter();
[163] da.SelectCommand = cmd; <-- add this
[164] da.Fill(ds);

Hope this helps if anyone else had this problem...




回答2:


i was having this problem and that line made it work....

Protected Sub searchButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchButton.Click
    Try
        Dim dt As New Data.DataTable
        Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("connection1").ToString())
        Dim cmd As New SqlCommand("getAllPerson", con)
        cmd.CommandType = Data.CommandType.StoredProcedure

        cmd.Parameters.Add("@id", Data.SqlDbType.Int).Value = CInt(SearchBox.Text)

        Dim da As New SqlDataAdapter
        da.SelectCommand = cmd
        da.Fill(dt)

        fnameTextBox.Text = dt.Rows(0).Item("FName")
        lnameTextBox.Text = dt.Rows(0).Item("LName")
        dobTextBox.Text = dt.Rows(0).Item("DOB")
        addressTextBox.Text = dt.Rows(0).Item("Address")
        address1TextBox.Text = dt.Rows(0).Item("Address1")
        contactTextbox.Text = dt.Rows(0).Item("ContactNo")
    Catch ex As Exception
        MsgBox(ex.Message.ToString())
    End Try

End Sub


来源:https://stackoverflow.com/questions/2044466/the-selectcommand-property-has-not-been-initialized-before-calling-fill

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!