473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Adding new column to dataset

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[i]["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

Nov 19 '05 #1
3 2392
is there anyone could help me?

Nov 19 '05 #2
I did not get your problema

"satria" <sa*****@gmail.com> escreveu na mensagem
news:11**********************@g14g2000cwa.googlegr oups.com...
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[i]["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

Nov 19 '05 #3
yes, just change ds.Tables["AccessLevel"] to ds.Tables[0] .
thx

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Eric Petruzzelli | last post by:
If I fill my dataset and there is no data. The dataset is still created with zero rows (all columns are there). When I add my first row using the script below, it takes over 2 seconds to add??? If...
0
by: juli jul | last post by:
Hello, I want a table with 2 columns in a dataset : my problem is that I have to add the values of the first column and only than the values of the secound (from the adapter) - but when adding the...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
2
by: dSchwartz | last post by:
I need help adding a column to a dataset, but its a little bit more complicated then just that. Here's the situation: I have many xml files in one directory, each which represent a newsletter. I...
6
by: Atley | last post by:
I have a Datagrid I have created, it's datasource is an XML Dataset that I have created. That form worked perfectly, until I had to add a column to the table... I did it in my database, it shows...
16
by: Geoff Jones | last post by:
Hi Can anybody help me with the following, hopefully simple, question? I have a table which I've connected to a dataset. I wish to add a new column to the beginning of the table and to fill...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
10
by: Bernie Yaeger | last post by:
I have a need to add a primary key to a dataset/datatable. How can this be done using a standard oledb data provider? Tx for any help.
0
by: James | last post by:
I have a source excel file which I'm reading into a dataset. This works just fine, the end user picks which sheet they want and I can access the data. But I'm trying to integrate a "First Row...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.