[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to catch sqlnull reference exception

Posted on 2011-10-19
2
Medium Priority
?
231 Views
Last Modified: 2012-05-12
I RUN MY APPLICATION AN GOT THE ERROR:
System.NullReferenceException: Object reference not set to an instance of an object
How do i catch this in my code. upload.docx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.WebControls;

namespace GambiaStat
{
    public partial class Showrejected : System.Web.UI.Page
    {
        public RadioButton RadioButton1;
        public RadioButton RadioButton2;
        public RadioButton RadioButton3;
        public RadioButton RadioButton4;
        public RadioButton RadioButton5;
        public RadioButton RadioButton6;
        public Calendar canlenderone, calendertwo;
        public GridView showgrid;


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                if (RadioButton1.Checked)
                {
                    ShowrejectAtBK01();
                }
                else if (RadioButton2.Checked)
                {
                    ShowrejectAtbBJL01();  
                }
                else if (RadioButton3.Checked)
                {
                    ShowrejectedAtBS01();
                }
                else if (RadioButton4.Checked)
                {
                    ShowrejectedAtFF01();

                }
                else
                {
                    ShowrejectAtSK01();
                }




        }
        
      

   

        void ShowrejectAtBK01()
        {

            SqlConnection dbconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["IDKitConnectionString_test_ec"].ToString());
            SqlCommand mycommand = new SqlCommand("SELECT NIN,Nationality,gender,ApprovalStatus, From Bio_data where DAY(DateCreated)=DAY(GETDATE() AND MONTH(DateCreated=MONTH(GETMONTH()AND YEAR(DateCreated=YEAR(GETYEAR()) AND  ApprovalStatus= 'Rejected' AND ReceiptNo like'450%'", dbconnection);

            SqlDataReader Retrieve_data;
            dbconnection.Open();
            Retrieve_data = mycommand.ExecuteReader();

            showgrid.DataSource = Retrieve_data;
            showgrid.DataBind();


        }
        void ShowrejectAtbBJL01()
        {

            SqlConnection dbconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["IDKitConnectionString_test_ec"].ToString());
            SqlCommand mycommand = new SqlCommand("SELECT NIN,Nationality,gender,ApprovalStatus From Bio_data where DAY(DateCreated)=DAY(GETDATE() AND MONTH(DateCreated=MONTH(GETMONTH()AND YEAR(DateCreated=YEAR(GETYEAR()) AND  ApprovalStatus= 'Rejected' AND ReceiptNo like'000%'", dbconnection);

            SqlDataReader Retrieve_data;
            dbconnection.Open();
            Retrieve_data = mycommand.ExecuteReader();

            showgrid.DataSource = Retrieve_data;
            showgrid.DataBind();


        }
        void ShowrejectAtSK01()
        {

            SqlConnection dbconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["IDKitConnectionString_test_ec"].ToString());
            SqlCommand mycommand = new SqlCommand("SELECT NIN,Nationality,gender,ApprovalStatus From Bio_data where DAY(DateCreated)=DAY(GETDATE() AND MONTH(DateCreated=MONTH(GETMONTH()AND YEAR(DateCreated=YEAR(GETYEAR()) AND  ApprovalStatus= 'Rejected' AND ReceiptNo like'200%'", dbconnection);

            SqlDataReader Retrieve_data;
            dbconnection.Open();
            Retrieve_data = mycommand.ExecuteReader();

            showgrid.DataSource = Retrieve_data;
            showgrid.DataBind();

        }
        void ShowrejectedAtFF01()
        {

            SqlConnection dbconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["IDKitConnectionString_test_ec"].ToString());
            SqlCommand mycommand = new SqlCommand("SELECT NIN,Nationality,gender,ApprovalStatus,ReceiptNo From Bio_data where DAY(DateCreated)=DAY(GETDATE() AND MONTH(DateCreated=MONTH(GETMONTH()AND YEAR(DateCreated=YEAR(GETYEAR()) AND  ApprovalStatus= 'Rejected' AND ReceiptNo like'600%'", dbconnection);

            SqlDataReader Retrieve_data;
            dbconnection.Open();
            Retrieve_data = mycommand.ExecuteReader();

            showgrid.DataSource = Retrieve_data;
            showgrid.DataBind();
        }
        void ShowrejectedAtBS01()
        {

            SqlConnection dbconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["IDKitConnectionString_test_ec"].ToString());
            SqlCommand mycommand = new SqlCommand("SELECT NIN,Nationality,gender,ApprovalStatus,ReceiptNo From Bio_data where DAY(DateCreated)=DAY(GETDATE() AND MONTH(DateCreated=MONTH(GETMONTH()AND YEAR(DateCreated=YEAR(GETYEAR()) AND  ApprovalStatus= 'Rejected' AND ReceiptNo like'550%'", dbconnection);

            SqlDataReader Retrieve_data;
            dbconnection.Open();
            Retrieve_data = mycommand.ExecuteReader();

            showgrid.DataSource = Retrieve_data;
            showgrid.DataBind();

        }


    }


}

Open in new window

0
Comment
Question by:Atouray
2 Comments
 
LVL 2

Accepted Solution

by:
owaisyahya earned 2000 total points
ID: 36993604
The connection string is null.try this method of writing connection string

	<connectionStrings>
		<add name="IDKitConnectionString_test_ec" connectionString="your_connection_string"/>
	</connectionStrings>

Open in new window


0
 

Author Closing Comment

by:Atouray
ID: 36993864
You very right.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question