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

AutoIdent

I am doing some data entry on a form which also a master/detail form. I have
2 textboxes and a dropdown box which allows you to enter the master
information for a "Route". The data for the route is fetched from a PostGres
database using NPGSQL objects for the data interface. This information is
stored in a dataset.

When i insert multiple records into this dataset i get a
"System.Data.ConstraintException: Column 'route_id' is constrained to be
unique. Value '' already exists" error I've read about the idea of setting
the incremement within the dataset to -1 so that this wouldn't be a problem.
However, this causes a problem when someone is inserting information then
into the details section of the form the master identity they end up sending
to the database is -1,-2,-3 etc...

Is there anyway to fetch the identity for each row that is inserted and
return that to the dataset i tried to create a stored procedure and return a
value and then bind that outbound parameter to the route_id column with no
success this was the code i used to try that.

RouteAdapter.InsertCommand = New
NpgsqlCommand("vts_insert_route(:a,:b,:c)", PGConnect)
RouteAdapter.InsertCommand.CommandType =
CommandType.StoredProcedure
With RouteAdapter.InsertCommand
.Parameters.Add(New NpgsqlParameter("a", DbType.String))
.Parameters.Add(New NpgsqlParameter("b", DbType.Int32))
.Parameters.Add(New NpgsqlParameter("c", DbType.String))
.Parameters.Add(New NpgsqlParameter("returnvalue",
DbType.Int32))
.Parameters(0).Direction = ParameterDirection.Input
.Parameters(1).Direction = ParameterDirection.Input
.Parameters(2).Direction = ParameterDirection.Input
.Parameters(3).Direction = ParameterDirection.ReturnValue

.Parameters(0).SourceColumn = "route_name"
.Parameters(1).SourceColumn = "school_id"
.Parameters(2).SourceColumn = "route_description"
.Parameters(3).SourceColumn = "route_id"
End With

Unfortunatley i can change the structure of the database or i would have
made the route_id a GUID.

------------------------------------
Gary Townsend
Database Developer
Spatial Mapping Ltd.
garyt[NADDASPAM]spatialmapping.com
remove [NADDASPAM] for email.

Jan 5 '06 #1
1 2221
I wrote an article "Managing an Identity Crisis" some time ago. It expect
that covers what you need.
See http://www.betav.com/msdn_magazine.htm
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Gary Townsend (Spatial Mapping Ltd.)" <ga************@spatialmapping.com>
wrote in message news:zLgvf.48510$OU5.42082@clgrps13...
I am doing some data entry on a form which also a master/detail form. I
have
2 textboxes and a dropdown box which allows you to enter the master
information for a "Route". The data for the route is fetched from a
PostGres
database using NPGSQL objects for the data interface. This information is
stored in a dataset.

When i insert multiple records into this dataset i get a
"System.Data.ConstraintException: Column 'route_id' is constrained to be
unique. Value '' already exists" error I've read about the idea of
setting
the incremement within the dataset to -1 so that this wouldn't be a
problem.
However, this causes a problem when someone is inserting information then
into the details section of the form the master identity they end up
sending
to the database is -1,-2,-3 etc...

Is there anyway to fetch the identity for each row that is inserted and
return that to the dataset i tried to create a stored procedure and return
a
value and then bind that outbound parameter to the route_id column with no
success this was the code i used to try that.

RouteAdapter.InsertCommand = New
NpgsqlCommand("vts_insert_route(:a,:b,:c)", PGConnect)
RouteAdapter.InsertCommand.CommandType =
CommandType.StoredProcedure
With RouteAdapter.InsertCommand
.Parameters.Add(New NpgsqlParameter("a", DbType.String))
.Parameters.Add(New NpgsqlParameter("b", DbType.Int32))
.Parameters.Add(New NpgsqlParameter("c", DbType.String))
.Parameters.Add(New NpgsqlParameter("returnvalue",
DbType.Int32))
.Parameters(0).Direction = ParameterDirection.Input
.Parameters(1).Direction = ParameterDirection.Input
.Parameters(2).Direction = ParameterDirection.Input
.Parameters(3).Direction = ParameterDirection.ReturnValue

.Parameters(0).SourceColumn = "route_name"
.Parameters(1).SourceColumn = "school_id"
.Parameters(2).SourceColumn = "route_description"
.Parameters(3).SourceColumn = "route_id"
End With

Unfortunatley i can change the structure of the database or i would have
made the route_id a GUID.

------------------------------------
Gary Townsend
Database Developer
Spatial Mapping Ltd.
garyt[NADDASPAM]spatialmapping.com
remove [NADDASPAM] for email.

Jan 7 '06 #2

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

Similar topics

2
by: Richard | last post by:
Hi Everyone, I have a table in which their is record which is exactly same. I want to delete all the duplicate keeping ony 1 record in a table. Example Table A Empid currentmonth ...
3
by: sameer | last post by:
Hi All, i have an asp.net application which has got sql server 2000 behind the scenes. Very simple application, all it does is extract the data from the databse and display it in the grid. But...
1
by: sgately | last post by:
HI All, I am not an HTML programmer, just used a template to create my website. On the website it had a built in Contact Form quickmail option. I do not know how to have information forwared to my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.