I have a web page which a user can insert their information (First Name, Last Name and Email) which works well. It writes this to an Access database.
All I want to do is prevent the user entering an email address which already exists! This would then ensure none of the fields were updated. (eg First Name, Last Name And Email). Basically, how do I avoid creating duplicates in the table!
Thanks
Dave
8 2286
Select the rows that match the email address, if you return > 0 then it already exists, and you can ignore it.
Set the Email field in the table to be unique? the ODBC driver will throw an exeption if a duplicate is attempted to insert
Thank you both for your replies. I set the table up to have a unique field (indexed according to Access) and this works by throwing the error which I can catch.
Red Son, how do match a row? I've worked out how to count rows, but not how to match. The code I use to match is
ds.Tables["BoardToBoard"].Rows.Count;
I would love to do ds.Tables["BoardToBoard"].Rows.["Email"] =="xxx";
Any suggestions?
Thank you again
Dave
I think he meant to do a select against your table and count the number of rows returned
SELECT count(*) FROM table WHERE email = @email
and if the return value is zero, the email address is unique. Otherwise it's not.
Or you could do a foreach loop in your table: - foreach (DataRow r in ds.Tables["BoardToBoard"])
-
{
-
if(r["Email"] == newEmailAddress)
-
//at this point, the email is non-unique and you should set some flag or return true
-
}
It would be better to do this on the database side though.
You could also use the .Select() on the datatable. -
DataRow[] matchingrows= ds.Tables["BoardToBoard"].Select("[email] = "+EmailToCheck);
-
if(matchingrows.Length == 0)
-
{//value is unique
-
}
-
Good point Plater, I forgot about that. Which do you think would be more efficient? Passing it off to the OleDb engine or doing it in memory from your program?
Again, thank you everyone for your helpful suggestions. This has answered many questions I had as well as my main question. Thank you
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Howard Hinnant |
last post by:
I recently asked for a survey of multimap insert with hint behavior, in
support of a paper I'm writing concerning lwg issue 233. My sincere
thanks to Beman Dawes, Raoul Gough, Russell Hind, Bronek...
|
by: Mark P |
last post by:
Some time ago I posted here about inserting into a set with a hint:
...
|
by: serge |
last post by:
I have a scenario where two tables are in a One-to-Many relationship
and I need to move the data from the Many table to the One table so
that it becomes a One-to-One relationship.
I need to...
|
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums...
|
by: Carl |
last post by:
Hi,
I hope someone can share some of their professional advice and help me out
with my embarissing problem concerning an Access INSERT query. I have never
attempted to create a table with...
|
by: Chris Kratz |
last post by:
Hello all,
We have run into what appears to be a problem with rules and subselects in
postgres 7.4.1. We have boiled it down to the following test case. If
anyone has any thoughts as to why...
|
by: Geoffrey KRETZ |
last post by:
Hello,
I'm wondering if the following behaviour is the correct one for
PostGreSQL (7.4 on UNIX).
I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching
the following request :...
|
by: MP |
last post by:
Hi
Posted this several hours ago to another ng but it never showed up thought
i'd try here.
using vb6, ado, .mdb, jet4.0, no access
given table tblJob with field JobNumber text(10)
'The...
|
by: lenygold via DBMonster.com |
last post by:
Hi everybody:
What is the best way to
I have 10 tables with similar INSERT requiremnts.
INSERT INTO ACSB.VAATAFAE
WITH AA(AA_TIN, AA_FILE_SOURCE_CD, .AA_TIN_TYP) AS
( SELECT AA_TIN,...
|
by: EJO |
last post by:
with sql 2000 enterprise
Trying to build a stored procedure that will take the rows of a parent
table, insert them into another table as well as the rows from a child
table to insert into...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
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...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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...
| |