Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


about sql database


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-12-2008, 06:34 AM
gjoisa's Avatar
Knows the basics
 
Join Date: Feb 2008
Location: Udupi , India
Posts: 53
Default about sql database

I have one sql database in my program. My database contains 9 fields . My database is about latitude longitude of places . Ex : Mumbai , 18 , 58 , N , 72 , 50 , E , 5 , 30 (Placename,lat degree,lat min, lat direction,long degree,long min,long direction,timezone hour,timezone minute) . The problem is , Database accepts the same data if it already exists in database . My requirement is , it should not accept the field1 data if it already exists .
Reply With Quote
  #2 (permalink)  
Old 05-12-2008, 09:37 AM
Junior Member
 
Join Date: Oct 2007
Location: Berkshire, UK
Posts: 29
Awards Showcase
Beta Tester 
Total Awards: 1
Default

If field1 is set as the PRIMARY KEY or a UNIQUE column, then it will not accept duplicate values. Personally I think it is best practice to test for duplicates before attempting an insert, so that you can nicely control the action. This is easily done with a small select:

cmd.CommandText = "SELECT ROWID from My_table WHERE Name = '" & txtName.Text & "'"
reader.Value = cmd.ExecuteReader
havedup = reader.ReadNextRow
reader.Close
If havedup Then
Msgbox(txtName.Text & " already exists!" & crlf & "Must be unique.",,cMsgBoxHand)
Return
End If


Geoff.
__________________
Geoffrey Looker
www.deeproot.co.uk
Reply With Quote
  #3 (permalink)  
Old 05-12-2008, 01:19 PM
gjoisa's Avatar
Knows the basics
 
Join Date: Feb 2008
Location: Udupi , India
Posts: 53
Default

I couldnot understand completely . can you please explain more with fully functioning example ?
Reply With Quote
  #4 (permalink)  
Old 05-15-2008, 08:17 AM
Junior Member
 
Join Date: Oct 2007
Location: Berkshire, UK
Posts: 29
Awards Showcase
Beta Tester 
Total Awards: 1
Default

I'll try to explain (sorry about the delay - been busy with other things).

A column may be defined as either the PRIMARY KEY or as UNIQUE. This is usually done when you create the table, either by an SQL command from B4ppc or with an external utility.

This column will then not accept duplicate values. If you try to insert record where the column value already exist, an "error" message will be produced - something like "Abort due to constraint violation column field1 is not unique".

In my opinion, it is best to handle this event before the error occurs, by testing for the value before attempting any insert - as in the sample code. Your program can then take the appropriate action. This test could be done regardless of how the column is defined.

Hope that helps,
Geoff.
__________________
Geoffrey Looker
www.deeproot.co.uk
Reply With Quote
  #5 (permalink)  
Old 05-16-2008, 07:50 AM
giannimaione's Avatar
Senior Member
 
Join Date: Apr 2007
Location: Naples, Italy
Posts: 134
Send a message via Skype™ to giannimaione
Awards Showcase
Beta Tester 
Total Awards: 1
Default try it

a little example
Attached Files
File Type: sbp sql.sbp (2.3 KB, 28 views)
__________________
Gianni Maione
Reply With Quote
  #6 (permalink)  
Old 05-16-2008, 10:40 AM
Junior Member
 
Join Date: Oct 2007
Location: Berkshire, UK
Posts: 29
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Thanks Gianni, an excellent example.
__________________
Geoffrey Looker
www.deeproot.co.uk
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 sql database gjoisa Questions & Help Needed 1 07-01-2008 10:06 AM
About SQL Database gjoisa Questions & Help Needed 12 02-23-2008 06:27 AM
how to create a database ? gjoisa Questions & Help Needed 27 02-14-2008 05:38 PM
UTF-8 Database EdQas Questions & Help Needed 5 10-16-2007 05:11 PM
How to convert an Access database to a sqlite database Peter Code Samples & Tips 5 07-24-2007 03:20 PM


All times are GMT. The time now is 07:27 AM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0