Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Thanked 0 Times in 0 Posts

    A problem:the failure to object reference to the targets set an example.

    hi,all.I am met a problem.can't fix it.
    And I have no idea how to transalted ,but use google language tool.so if it makes any mistake ,forgive me.

    Error : the failure to object reference to the targets set an example.
    Note : implementation of the current Web request, there untreated abnormal. Please check stack tracking information to understand the code and the error led to the wrong source of detailed information.
    Extremely detailed information : System.NullReferenceException : failure to object reference to the targets set an example.
    Source mistakes :
    line 42 :
    line 43 : // DataGrid with data shows.
    line 44 : if (myDataSet.Tables[ "bbs_infomation" ].Ro ws.Count = 0)
    line 45 : {
    line 46 : myDataSet.Tables[ DataGrid1.DataSource = "bbs_information "].DefaultView;

    it shows that line 44 has problem,but I can't find it.
    so this is the code:
    //Use Connection to connect the database。 
            string connStr = System.Configuration.ConfigurationSettings.AppSettings["connString"]; 
            SqlConnection myConnection = new SqlConnection(connStr); 
            //Use DataAdapter to visit the table 。 
            string queryStr = "select * from bbs_information where parentid=0 order by datetime desc"; 
            SqlDataAdapter myDataAdapter = new SqlDataAdapter(queryStr, myConnection); 
            //Use DataSet to store the table。 
            DataSet myDataSet = new DataSet(); 
            //Use DataGrid to display data。 
            if (myDataSet.Tables["bbs_infomation"].Rows.Count != 0) 
                DataGrid1.DataSource = myDataSet.Tables["bbs_information"].DefaultView; 
                Label1.Text += "(No words leave to you!)"; 
        protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e) 
            DataGrid1.CurrentPageIndex = e.NewPageIndex; 
    I am sorry for my poor enlish,but I have no choice.
    Thank you,
    Last edited by lxy.bhbh; 05-03-2007 at 03:02 PM.

  • #2
    New Coder
    Join Date
    Mar 2007
    Thanked 0 Times in 0 Posts
    as far as I can interpret this, it says reference to an object not set to an instance of an object

    so try this: run the query directly on the database, if it returns nothing, that's where your problem is.

    If I am not mistaken, if the query returns nothing, the dataset will be set to null, so you wont have a row count. If there are any chances of having empty results, try changing your line 44
    if (myDataSet.Tables["bbs_infomation"].Rows.Count != 0)

    if (myDataSet.Tables["bbs_infomation"] != null)
    hope that helped =)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts