obj ref error

im getting the dreaded:
Object reference not set to an instance of an object.
on the code below. pretty new to C# but i know im missing something basic here.

any help is appreciated
thanks
rik

public void GetEEs()
{

SqlConnection myConnection = new SqlConnection("Data Source=(Local);Initial Catalog=A39;Integrated Security=SSPI");
SqlDataAdapter da = new SqlDataAdapter("GetAuditTimeCard",myConnection);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add("@PERIOD",SqlDbType.DateTime,8);
da.SelectCommand.Parameters["@PERIOD"].Value = txtPpe.Text;
DataSet ds = new DataSet();
myConnection.Open();
da.Fill(ds);
Dg1.DataSource = ds.Tables["TimeCard"].DefaultView;
Dg1.DataBind();
da.Dispose();
myConnection.Close();
}

Comments

  • You need to assign a sql command object to the SelectCommand first.

    [code]
    da.SelectCommand = New SqlCommand();
    [/code]

    : im getting the dreaded:
    : Object reference not set to an instance of an object.
    : on the code below. pretty new to C# but i know im missing something basic here.
    :
    : any help is appreciated
    : thanks
    : rik
    :
    : public void GetEEs()
    : {
    :
    : SqlConnection myConnection = new SqlConnection("Data Source=(Local);Initial Catalog=A39;Integrated Security=SSPI");
    : SqlDataAdapter da = new SqlDataAdapter("GetAuditTimeCard",myConnection);
    : da.SelectCommand.CommandType = CommandType.StoredProcedure;
    : da.SelectCommand.Parameters.Add("@PERIOD",SqlDbType.DateTime,8);
    : da.SelectCommand.Parameters["@PERIOD"].Value = txtPpe.Text;
    : DataSet ds = new DataSet();
    : myConnection.Open();
    : da.Fill(ds);
    : Dg1.DataSource = ds.Tables["TimeCard"].DefaultView;
    : Dg1.DataBind();
    : da.Dispose();
    : myConnection.Close();
    : }
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion