473,382 Members | 1,355 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,382 software developers and data experts.

auto incr

hi
i have created a dataset manually.
is ther any way to have auto increment in it?
Nov 16 '05 #1
2 1815
Yes, whichever DataColumn in whatever DataTable, set it's AutoIncrement
Property to true. Then there's a AutoIncrementStep value which sets the
amount that each increment will be and theAutoIncrementSeed which is the
starting point. To Avoid colisions if this is a multiuser app, set the Step
to -1 and the seed to 0 that way the RDBMS will always automatically choose
an available value and you won't have any collisions.

HTH,

Bill

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
"frazer" <ic***@hotmail.com> wrote in message
news:ux*************@TK2MSFTNGP12.phx.gbl...
hi
i have created a dataset manually.
is ther any way to have auto increment in it?

Nov 16 '05 #2
frazer wrote:
i have created a dataset manually.
is ther any way to have auto increment in it?


Hi frazer,

look at the following code:

private void button1_Click(object sender, System.EventArgs e)
{
//create a new DataSet
DataSet ds = new DataSet();
//add a table
DataTable dt = ds.Tables.Add();
//add a column
DataColumn dc = dt.Columns.Add("ID");
//this shall be an autoincrement column
dc.AutoIncrement = true;
dc.AutoIncrementSeed = 1;
dc.AutoIncrementStep = 1;

//another column
DataColumn dc2 = dt.Columns.Add("test");
dc2.DataType = typeof(string);
//fill the table
for (int i = 0; i < 10; i++)
{
DataRow dr = dt.NewRow();
dr["test"] = "test" + i;
dt.Rows.Add(dr);
}

//show autogenerated ids
foreach (DataRow dr in dt.Rows)
{
System.Diagnostics.Debug.WriteLine("ID: " + dr["ID"].ToString() +
", test: " + dr["test"].ToString());
}
}

Cheers

Arne Janning
Nov 16 '05 #3

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

Similar topics

2
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code...
1
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the...
5
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge...
20
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
5
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the...
5
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
5
by: Xiaolei | last post by:
Hi, I'm trying to plot some points in an image. Each point has an associating type and I'd like to have different colors (preferrably of high contrast) for different types. The number of types...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.