473,401 Members | 2,127 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,401 software developers and data experts.

Database, DataSet, AutoNumber,.... Help ??

Hi everyone

I'm devloping a wep application which needs to access database frequently
(for now access database). I got stuck.

The first page, I ask for several questions from customers and holds their
answers. Let make it simple, the questions are

Name:
Address
Phone
Email:
In database has:
ID Name Address Phone Email

ID is a counter which will increment automatically after I insert the the
row

There is another table which reuses the ID from the table above
ID ABC DEF GHI

I would like to know what is the idea behind this solutions. I want to know
right after I insert the record including Name,Address,Phone,Email. I want
to have the ID right after that, store it somewhere for later use.

Thanks for any help
Nov 18 '05 #1
3 1081
You can use "SELECT SCOPE_IDENTITY()" or "SELECT @@IDENTITY" to select the
value back. Use the SqlCommand.ExecuteScalar() method.

I hope this helps.

--
Regards,

Felix Wang

"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message
news:uq**************@TK2MSFTNGP09.phx.gbl...
Hi everyone

I'm devloping a wep application which needs to access database frequently
(for now access database). I got stuck.

The first page, I ask for several questions from customers and holds their
answers. Let make it simple, the questions are

Name:
Address
Phone
Email:
In database has:
ID Name Address Phone Email

ID is a counter which will increment automatically after I insert the the
row

There is another table which reuses the ID from the table above
ID ABC DEF GHI

I would like to know what is the idea behind this solutions. I want to know right after I insert the record including Name,Address,Phone,Email. I want
to have the ID right after that, store it somewhere for later use.

Thanks for any help

Nov 18 '05 #2
I am not sure about this reply. I am just attempting a
solution as I noticed that no one else has responded.

I haven't really understood your question. Do you just
want to know the ID of the record you just insert?
use "SELECT @@IDENTITY" to return the ID of the record
you just insert

But note that this has to be done using the same
CONNECTION u used for inserting the statement.

The following is fine:

sqlConnection.Open ();
sqlCommand.CommandText = "INSERT INTO Table (a, b) VALUES
(10,20);SELECT @@IDENTITY);

object id;
id = sqlCommand.ExecuteScalar();

int myID = Convert.ToInt32 (id);

sqlConnection.Close ();

You also mentioned something about accessing the
database "frequently". If this was your problem, then try
caching the dataset.

Regards,

Michelle

-----Original Message-----
Hi everyone

I'm devloping a wep application which needs to access database frequently(for now access database). I got stuck.

The first page, I ask for several questions from customers and holds theiranswers. Let make it simple, the questions are

Name:
Address
Phone
Email:
In database has:
ID Name Address Phone Email

ID is a counter which will increment automatically after I insert the therow

There is another table which reuses the ID from the table aboveID ABC DEF GHI

I would like to know what is the idea behind this solutions. I want to knowright after I insert the record including Name,Address,Phone,Email. I wantto have the ID right after that, store it somewhere for later use.
Thanks for any help
.

Nov 18 '05 #3
Thank you so much. It works great
"Michelle Stone" <mi********@yahoo.com> wrote in message
news:02****************************@phx.gbl...
I am not sure about this reply. I am just attempting a
solution as I noticed that no one else has responded.

I haven't really understood your question. Do you just
want to know the ID of the record you just insert?
use "SELECT @@IDENTITY" to return the ID of the record
you just insert

But note that this has to be done using the same
CONNECTION u used for inserting the statement.

The following is fine:

sqlConnection.Open ();
sqlCommand.CommandText = "INSERT INTO Table (a, b) VALUES
(10,20);SELECT @@IDENTITY);

object id;
id = sqlCommand.ExecuteScalar();

int myID = Convert.ToInt32 (id);

sqlConnection.Close ();

You also mentioned something about accessing the
database "frequently". If this was your problem, then try
caching the dataset.

Regards,

Michelle

-----Original Message-----
Hi everyone

I'm devloping a wep application which needs to access

database frequently
(for now access database). I got stuck.

The first page, I ask for several questions from

customers and holds their
answers. Let make it simple, the questions are

Name:
Address
Phone
Email:
In database has:
ID Name Address Phone Email

ID is a counter which will increment automatically after

I insert the the
row

There is another table which reuses the ID from the

table above
ID ABC DEF GHI

I would like to know what is the idea behind this

solutions. I want to know
right after I insert the record including

Name,Address,Phone,Email. I want
to have the ID right after that, store it somewhere for

later use.

Thanks for any help
.

Nov 18 '05 #4

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

Similar topics

1
by: Joanna | last post by:
I am developing a database to track inspections conducted on homes. I have two main types of inspections, Punch & Final; however Final inspections have 3 possible sub-categories: failed, with...
5
by: deko | last post by:
I've heard it's best to have a meaningless primary key (such as an autonumber field) as opposed to a pk that contains volatile data. This sounds reasonable enough. In fact, I think I'd need a...
0
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
10
by: Jim Devenish | last post by:
I have a split front end/back end system. However I create a number of local tables to carry out certain operations. There is a tendency for the front end to bloat so I have set 'compact on...
3
by: Paez | last post by:
Hi there. Anybody knows if is it possible to reverse a dataset? Lets say, if the dataSet has 10 rows, row 1 will row 10 and row 10 will be 1 and so on... Thanks in advance. Paez
1
by: sjvandevoorde | last post by:
II am hoping someone out there will be able to give me some guidance, as I am about to give up. I have been working on this for some time and I think I have looked at it so much that I can't even...
2
by: babai28 | last post by:
Hi, I have a table in MS Acsess. The table has an Auto Number Primary key. I have to use disconnected architechture using a bound data Grid View from a data Display form. After adding rows when I...
0
by: Finn Stampe Mikkelsen | last post by:
Hi I've several times run into to the following event... I've designed a database, using access and Autonumber type field as the primary key. I use DataGridViews with bindingsources and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.