Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. My Ado.Net code is on a Public Holiday

My Ado.Net code is on a Public Holiday

Scheduled Pinned Locked Moved C#
databasecsharpsharepointgraphics
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Vimalsoft Pty Ltd

    Good Afternoon All As you know in South Africa today is a Election day, i think my ado.net code went to the Elections tooo i have this code in my DAL

    public DataSet Lis_Databases(String DB)
    {

            Strcon = GetConnectionString(DB);
    
    
            con = new SqlConnection(Strcon);
    
            cmdselect = new SqlCommand();
    
            cmdselect.CommandText = "\[dbo\].\[sp\_ListDatabasesOfType\_Booking\]";
    
            cmdselect.CommandType = CommandType.StoredProcedure;
    
            cmdselect.Connection = con;
    
            da = new SqlDataAdapter();
    
            da.SelectCommand = cmdselect;
    
            DataSet ds = new DataSet();
    
            try
            {
                con.Open();
    
                da.Fill(ds);
            }
            catch (SqlException)
            {
                throw;
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
    
            return ds;
    
        }
    

    and i call this code in my BLL like this

    public DataSet Lis_Databases(String DB)
    {
    DAL.DAL obj = new DAL.DAL();

            DataSet ds = new DataSet();
    
            try
            {
                ds = obj.Lis\_Databases(DB);
            }
            catch (SqlException)
            {   
                throw;
            }
            finally
            {
    
                obj = null;
            }
            return ds;
           
        }
    

    And call use it like this in my PL(Presention Layer)

    private void List_Databases_Grid()
    {

            BLL.BLL obj = new BLL.BLL();
        
            DataSet ds = new DataSet();
    
        try
        {
    
            ds = obj.Lis\_Databases(Convert.ToString(Session\["ActiveDatabase"\]));
    
            if (ds.Tables\[0\].Rows.Count > 0)
            {
                GridView\_Database\_list.DataSource = ds;
    
                GridView\_Database\_list.DataBind();
            }
            else
            {
                lblMessage.Text = "No Booking Database Avaiable,Create one";
                lblMessage.Visible = true;
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
        catch (SqlException ex)
        {
            lblMessage.Visible = true;
            lblMessage.Text = "The List cannot be Binded, Please Contact ITS" + ex.Message;
            lblMessage.ForeCol
    
    M Offline
    M Offline
    Mbah Dhaim
    wrote on last edited by
    #2

    Vuyiswa Maseko wrote:

    if (ds.Tables[0].Rows.Count > 0){

    change that code to if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0){ hope it helps

    dhaim ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro" in the front line gave a lead, in the middle line build goodwill, in the behind give power support

    V 1 Reply Last reply
    0
    • M Mbah Dhaim

      Vuyiswa Maseko wrote:

      if (ds.Tables[0].Rows.Count > 0){

      change that code to if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0){ hope it helps

      dhaim ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro" in the front line gave a lead, in the middle line build goodwill, in the behind give power support

      V Offline
      V Offline
      Vimalsoft Pty Ltd
      wrote on last edited by
      #3

      Good Day Mbah Dhaim I have added such a Code to Check if there any rows and your code will check if there any tables in the dataset. but my Problem is here

      GridView_Database_list.DataSource = ds;

      i get

      Object reference not set to an instance of an object.

      Error Thank you

      Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

      G L M 3 Replies Last reply
      0
      • V Vimalsoft Pty Ltd

        Good Day Mbah Dhaim I have added such a Code to Check if there any rows and your code will check if there any tables in the dataset. but my Problem is here

        GridView_Database_list.DataSource = ds;

        i get

        Object reference not set to an instance of an object.

        Error Thank you

        Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

        G Offline
        G Offline
        Greg Chelstowski
        wrote on last edited by
        #4

        OK, which object is it failing on, the gridview or the dataset? (I don't see how it could possibly fail on the dataset though). Is the Gridview actually in your controls collection? Do you add it dynamically (in which case, before you add it do you actually instantiate it properly?) or is it a control in your aspx page? And if so, if you're using frames are you not trying to access a control that is in a different frame? Or maybe the gridview is in a content holder of and you're trying to access it from a master page?

        var question = (_2b || !(_2b));

        V 1 Reply Last reply
        0
        • V Vimalsoft Pty Ltd

          Good Day Mbah Dhaim I have added such a Code to Check if there any rows and your code will check if there any tables in the dataset. but my Problem is here

          GridView_Database_list.DataSource = ds;

          i get

          Object reference not set to an instance of an object.

          Error Thank you

          Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #5

          According to your logic, ds can't be empty. I guess that you already added a watch to verify that. Let's break the statement that the compiler is complaining about into some smaller parts;

          GridView_Database_list.DataSource = ds;

          Could it be that "GridView_Database_list" is null? Assigning a null-value to a variable isn't likely to cause errors, but assigning a value to something that is null, probably will. --edit-- Read Greg's post - he's right in noticing that there may be some action triggered from the Grid itself once there is an assignment to the DataSource property :)

          I are troll :)

          V 1 Reply Last reply
          0
          • V Vimalsoft Pty Ltd

            Good Day Mbah Dhaim I have added such a Code to Check if there any rows and your code will check if there any tables in the dataset. but my Problem is here

            GridView_Database_list.DataSource = ds;

            i get

            Object reference not set to an instance of an object.

            Error Thank you

            Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

            M Offline
            M Offline
            Mbah Dhaim
            wrote on last edited by
            #6

            DataSet is referenced type, as you see in your BLL and PL in finally part you destroy your object (DAL and BLL) : finally {obj = null}, your dataset in PL will be lost reference too. remove finally part of your code. hope it helps

            dhaim ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro" in the front line gave a lead, in the middle line build goodwill, in the behind give power support

            V 1 Reply Last reply
            0
            • L Lost User

              According to your logic, ds can't be empty. I guess that you already added a watch to verify that. Let's break the statement that the compiler is complaining about into some smaller parts;

              GridView_Database_list.DataSource = ds;

              Could it be that "GridView_Database_list" is null? Assigning a null-value to a variable isn't likely to cause errors, but assigning a value to something that is null, probably will. --edit-- Read Greg's post - he's right in noticing that there may be some action triggered from the Grid itself once there is an assignment to the DataSource property :)

              I are troll :)

              V Offline
              V Offline
              Vimalsoft Pty Ltd
              wrote on last edited by
              #7

              Thanks for your Reply The Gridview is Clean , there is nothing Assign to it.

              Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

              1 Reply Last reply
              0
              • G Greg Chelstowski

                OK, which object is it failing on, the gridview or the dataset? (I don't see how it could possibly fail on the dataset though). Is the Gridview actually in your controls collection? Do you add it dynamically (in which case, before you add it do you actually instantiate it properly?) or is it a control in your aspx page? And if so, if you're using frames are you not trying to access a control that is in a different frame? Or maybe the gridview is in a content holder of and you're trying to access it from a master page?

                var question = (_2b || !(_2b));

                V Offline
                V Offline
                Vimalsoft Pty Ltd
                wrote on last edited by
                #8

                Thank you Greg The GridView was inside the UpdateProgress Control :rolleyes: My Mistake, Thank you.

                Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

                1 Reply Last reply
                0
                • M Mbah Dhaim

                  DataSet is referenced type, as you see in your BLL and PL in finally part you destroy your object (DAL and BLL) : finally {obj = null}, your dataset in PL will be lost reference too. remove finally part of your code. hope it helps

                  dhaim ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro" in the front line gave a lead, in the middle line build goodwill, in the behind give power support

                  V Offline
                  V Offline
                  Vimalsoft Pty Ltd
                  wrote on last edited by
                  #9

                  No No the Finally Part will only Destroy the object not the Dataset, the Dataset will be Teturned Correctly. Thank you for your help i have the problem The GridView was inside the UpdateProgress Control :rolleyes: My Mistake, Thank you.

                  Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

                  M 1 Reply Last reply
                  0
                  • V Vimalsoft Pty Ltd

                    No No the Finally Part will only Destroy the object not the Dataset, the Dataset will be Teturned Correctly. Thank you for your help i have the problem The GridView was inside the UpdateProgress Control :rolleyes: My Mistake, Thank you.

                    Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

                    M Offline
                    M Offline
                    Mbah Dhaim
                    wrote on last edited by
                    #10

                    Vuyiswa Maseko wrote:

                    My Mistake, Thank you.

                    you're welcome this day i learn that referenced type will not destroy although its parent destroyed. thank you very much.

                    dhaim ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro" in the front line gave a lead, in the middle line build goodwill, in the behind give power support

                    V 1 Reply Last reply
                    0
                    • M Mbah Dhaim

                      Vuyiswa Maseko wrote:

                      My Mistake, Thank you.

                      you're welcome this day i learn that referenced type will not destroy although its parent destroyed. thank you very much.

                      dhaim ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro" in the front line gave a lead, in the middle line build goodwill, in the behind give power support

                      V Offline
                      V Offline
                      Vimalsoft Pty Ltd
                      wrote on last edited by
                      #11

                      You are Welcome :)

                      Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups