Adding new column to dataset

Discussion in 'ASP .Net' started by satria, Oct 13, 2005.

  1. satria

    satria Guest

    hi all,

    i have a accesslevel table's that has 2 field, id and accesslevelname.
    i successfully binded the table to datagrid, but i'd like to display a
    new column, called number. so it 'll display :
    number | accesslevelname
    1 user
    2 supervisor
    ....

    i dont want to add the new column to the database.

    i tried this code :
    DataSet ds=new DataSet();
    ds=CFM.component.accesslevel.GetDS();
    DataTable table = ds.Tables["AccessLevel"];
    table.Columns.Add(new DataColumn("no",typeof(int)));
    int rowcount=table.Rows.Count;
    for(int i=1;i<rowcount-1;i++)
    {
    table.Rows["no"]=i;
    }

    DataGrid1.DataSource=table;
    DataGrid1.DataBind();

    but i always get error
    "Object reference not set to an instance of an object." at line
    "table.Columns.Add(new DataColumn("no",typeof(int)));".

    pls hlp me

    regards

    satria
     
    satria, Oct 13, 2005
    #1
    1. Advertising

  2. satria

    satria Guest

    is there anyone could help me?
     
    satria, Oct 13, 2005
    #2
    1. Advertising

  3. satria

    ViewState Guest

    I did not get your problema

    "satria" <> escreveu na mensagem
    news:...
    > hi all,
    >
    > i have a accesslevel table's that has 2 field, id and accesslevelname.
    > i successfully binded the table to datagrid, but i'd like to display a
    > new column, called number. so it 'll display :
    > number | accesslevelname
    > 1 user
    > 2 supervisor
    > ...
    >
    > i dont want to add the new column to the database.
    >
    > i tried this code :
    > DataSet ds=new DataSet();
    > ds=CFM.component.accesslevel.GetDS();
    > DataTable table = ds.Tables["AccessLevel"];
    > table.Columns.Add(new DataColumn("no",typeof(int)));
    > int rowcount=table.Rows.Count;
    > for(int i=1;i<rowcount-1;i++)
    > {
    > table.Rows["no"]=i;
    > }
    >
    > DataGrid1.DataSource=table;
    > DataGrid1.DataBind();
    >
    > but i always get error
    > "Object reference not set to an instance of an object." at line
    > "table.Columns.Add(new DataColumn("no",typeof(int)));".
    >
    > pls hlp me
    >
    > regards
    >
    > satria
    >
     
    ViewState, Oct 13, 2005
    #3
  4. satria

    satria Guest

    yes, just change ds.Tables["AccessLevel"] to ds.Tables[0] .
    thx
     
    satria, Oct 13, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Do
    Replies:
    2
    Views:
    6,181
    Natty Gur
    Nov 16, 2003
  2. dSchwartz
    Replies:
    2
    Views:
    2,203
    dSchwartz
    Mar 1, 2004
  3. =?Utf-8?B?QXNoYQ==?=

    adding new column to a dataset.

    =?Utf-8?B?QXNoYQ==?=, Aug 11, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    3,418
    =?Utf-8?B?QXNoYQ==?=
    Aug 11, 2004
  4. James
    Replies:
    0
    Views:
    520
    James
    Sep 21, 2006
  5. Meir Rotfleisch

    adding droplist as column from returned Dataset

    Meir Rotfleisch, Nov 30, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    135
    Meir Rotfleisch
    Nov 30, 2003
Loading...

Share This Page