Click here to Skip to main content
16,011,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,
Iam getting an error on this page.Please,help me to find why this is coming out there...
Here Iam getting the error:
C#
da.SelectCommand.Parameters.AddWithValue("@d1", Application["checkin"].ToString());

 SqlDataAdapter da = new SqlDataAdapter("select Single_Room from Deluxe where date1 between @d1 and @d2 and Single_Room!=0", con);
        da.SelectCommand.Parameters.AddWithValue("@d1", Application["checkin"].ToString());
        da.SelectCommand.Parameters.AddWithValue("@d2", Application["checkout"].ToString());
        DataSet ds = new DataSet();
        da.Fill(ds);
        int count = ds.Tables[0].Rows.Count;
        int singleromm = 0;

        for (int i = 0; i < count; i++)
        {
            singleromm = singleromm + Convert.ToInt32(ds.Tables[0].Rows[i][0]);
        }

        if (singleromm >= 2)
        {
            TextBox22.Enabled = false;
            TextBox22_NumericUpDownExtender.Enabled = false;
        }
        else
        {
            TextBox22.Enabled = true;
            TextBox22_NumericUpDownExtender.Enabled = true;

        }
Posted
Updated 20-Mar-14 21:02pm
v2

In your case the error happens because of Application["checkin"].ToString() is Null.Assign a value to this.

please see:Object reference not set to an instance of an object[^]
 
Share this answer
 
Try to open connection first

C#
con.open();
SqlDataAdapter da = new SqlDataAdapter("select Single_Room from Deluxe where date1 between @d1 and @d2 and Single_Room!=0", con);
 
Share this answer
 
Try this.. :)

C#
SqlDataAdapter da = new SqlDataAdapter("select Single_Room from Deluxe where date1 between @d1 and @d2 and Single_Room!=0", con);
        da.SelectCommand.Parameters.AddWithValue("@d1",Convert.ToString(Application["checkin"]));
       da.SelectCommand.Parameters.AddWithValue("@d2",Convert.ToString(Application["checkout"]));
        DataSet ds = new DataSet();
        da.Fill(ds);
        int count = ds.Tables[0].Rows.Count;
        int singleromm = 0;
 
        for (int i = 0; i < count; i++)
        {
            singleromm = singleromm + Convert.ToInt32(ds.Tables[0].Rows[i][0]);
        }
 
        if (singleromm >= 2)
        {
            TextBox22.Enabled = false;
            TextBox22_NumericUpDownExtender.Enabled = false;
        }
        else
        {
            TextBox22.Enabled = true;
            TextBox22_NumericUpDownExtender.Enabled = true;
 
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900