PC Review


Reply
Thread Tools Rate Thread

Controlling a primary key column

 
 
=?Utf-8?B?SmF2aWVy?=
Guest
Posts: n/a
 
      1st Aug 2005
Hello:
I have an application with a data base. i insert information by the
application in the data base, and i have to control that the user doesn't
give a value for the primary key column that already exists.
I would want to know what happens in that case, when you try to insert a new
row in the table with a value for the primary key that already exists, an
exception is raised? nothing happens? it happens an updated?
Thanks for the help.
Bye.
 
Reply With Quote
 
 
 
 
Sahil Malik [MVP]
Guest
Posts: n/a
 
      1st Aug 2005
What database are you using?

Are you executing the DbCommand (SqlCommand/OracleCommand etc.) Directly or
are you using a DataAdapter?

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
-------------------------------------------------------------------------------------------

"Javier" <(E-Mail Removed)> wrote in message
news:FE8303C3-C7C7-4C50-BCBE-(E-Mail Removed)...
> Hello:
> I have an application with a data base. i insert information by the
> application in the data base, and i have to control that the user doesn't
> give a value for the primary key column that already exists.
> I would want to know what happens in that case, when you try to insert a
> new
> row in the table with a value for the primary key that already exists, an
> exception is raised? nothing happens? it happens an updated?
> Thanks for the help.
> Bye.



 
Reply With Quote
 
Marina
Guest
Posts: n/a
 
      1st Aug 2005
The same thing happens that would happen if you were to run the query
directly on the database.

The row would not get added, and an error would be raised.

What your application should do, is to check whether or not the primary key
the user provided is already taken or not. If not, proceed. Otherwise, show
the user an error message.

"Javier" <(E-Mail Removed)> wrote in message
news:FE8303C3-C7C7-4C50-BCBE-(E-Mail Removed)...
> Hello:
> I have an application with a data base. i insert information by the
> application in the data base, and i have to control that the user doesn't
> give a value for the primary key column that already exists.
> I would want to know what happens in that case, when you try to insert a
> new
> row in the table with a value for the primary key that already exists, an
> exception is raised? nothing happens? it happens an updated?
> Thanks for the help.
> Bye.



 
Reply With Quote
 
=?Utf-8?B?SmF2aWVy?=
Guest
Posts: n/a
 
      1st Aug 2005
Hello:
I use SQL Server Desktop Edition in a PocketPC client, and i have a similar
code in the server, but in the server i use DBF (make with Visual FoxPro, i
believe) by OleDb connector. I execute the command directly, i create the SQL
sentence in a string, load it in the Command and then call to
executeNonQuery method.
Thanks for your help.
Bye.
"Sahil Malik [MVP]" wrote:

> What database are you using?
>
> Are you executing the DbCommand (SqlCommand/OracleCommand etc.) Directly or
> are you using a DataAdapter?
>
> - Sahil Malik [MVP]
> ADO.NET 2.0 book -
> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
> -------------------------------------------------------------------------------------------
>
> "Javier" <(E-Mail Removed)> wrote in message
> news:FE8303C3-C7C7-4C50-BCBE-(E-Mail Removed)...
> > Hello:
> > I have an application with a data base. i insert information by the
> > application in the data base, and i have to control that the user doesn't
> > give a value for the primary key column that already exists.
> > I would want to know what happens in that case, when you try to insert a
> > new
> > row in the table with a value for the primary key that already exists, an
> > exception is raised? nothing happens? it happens an updated?
> > Thanks for the help.
> > Bye.

>
>
>

 
Reply With Quote
 
=?Utf-8?B?SmF2aWVy?=
Guest
Posts: n/a
 
      1st Aug 2005
Hello:
I had though about what you tell me, but i see a problem, i would have to do
two access to the database, and this will penalize the performance, specially
in the PocketPC application. That's because i prefer to control the exception
raised or a similar solution solution instead of accesing two times to the
database.
Thank you for your help.
Bye.

"Marina" wrote:

> The same thing happens that would happen if you were to run the query
> directly on the database.
>
> The row would not get added, and an error would be raised.
>
> What your application should do, is to check whether or not the primary key
> the user provided is already taken or not. If not, proceed. Otherwise, show
> the user an error message.
>
> "Javier" <(E-Mail Removed)> wrote in message
> news:FE8303C3-C7C7-4C50-BCBE-(E-Mail Removed)...
> > Hello:
> > I have an application with a data base. i insert information by the
> > application in the data base, and i have to control that the user doesn't
> > give a value for the primary key column that already exists.
> > I would want to know what happens in that case, when you try to insert a
> > new
> > row in the table with a value for the primary key that already exists, an
> > exception is raised? nothing happens? it happens an updated?
> > Thanks for the help.
> > Bye.

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
controlling the sequence number (primary key) Capt James Cook Microsoft Access Database Table Design 2 25th Aug 2009 11:51 PM
Linking To .XLS: Controlling Column's DataType? PeteCresswell Microsoft Access 0 20th Feb 2009 04:17 PM
Controlling Column Heights toddcarew@gmail.com Microsoft C# .NET 4 15th Feb 2007 03:32 AM
Primary Key, Identity Column - Problem adding row to strongly typed data table - "Column 'ShipmentID' does not allow nulls." stephanieschipper@yahoo.com Microsoft ADO .NET 0 12th Dec 2006 02:14 AM
Controlling datagrid column width when there are no records. weaklingX@hotmail.com Microsoft ASP .NET 1 12th Sep 2006 10:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:02 AM.