Hi,
I want to check in the below code if the email exists in the database before inserting. How can I do that? -
Dim EmailAlertDataSource As New SqlDataSource()
-
EmailAlertDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("DB_EmailAlertConnectionString1").ToString()
-
-
EmailAlertDataSource.InsertCommandType = SqlDataSourceCommandType.Text
-
EmailAlertDataSource.InsertCommand = "INSERT INTO Table_Emails (EmailAccount, EmailAccountDateEntered, EmailCategory) VALUES (@EmailAccount, @EmailAccountDateEntered, @EmailCategory)"
-
EmailAlertDataSource.InsertParameters.Add("EmailAccount", tbemail.Text) 'HOW TO CHECK THIS EMAIL EXISTS IN DATABASE??
-
EmailAlertDataSource.InsertParameters.Add("EmailAccountDateEntered", DateTime.Now.ToString("f", New CultureInfo("en-GB")))
-
-
Dim MyItem As ListItem
-
Dim catSelected As String = ""
-
Dim catSelected1 As String = ""
-
'Dim r As Integer
-
For Each MyItem In CheckBoxList1.Items
-
If MyItem.Selected = True Then
-
catSelected = catSelected & MyItem.Text & ","
-
Dim i As Integer = Len(catSelected)
-
catSelected1 = Mid(catSelected, 1, i - 1)
-
'lblMessage.Text = catSelected1
-
End If
-
Next
-
-
EmailAlertDataSource.InsertParameters.Add("EmailCategory", catSelected1)
-
-
Dim rowsAffected As Integer = 0
-
-
Try
-
-
rowsAffected = EmailAlertDataSource.Insert()
-
-
Catch ex As Exception
-
-
-
'Response.Write("<p>strTime:" & strTime)
-
lblError.Text = "An error has occured/"
-
lblError.Text += ex.Message()
-
-
-
'TODO: To create this page
-
'Server.Transfer("email_problem_new.aspx")
-
-
Finally
-
-
EmailAlertDataSource = Nothing
-
-
End Try
-
-
If rowsAffected <> 1 Then
-
-
'Server.Transfer("email_problem_new.aspx")
-
-
Else
-
-
'Server.Transfer("email_confirm_new.aspx")
-
-
End If
-
3 7402
create a select command which gets the records based on the email.
If the number of records is more than zero, then the email already exists !!!
Hi,
I want to check in the below code if the email exists in the database before inserting. How can I do that? -
Dim EmailAlertDataSource As New SqlDataSource()
-
EmailAlertDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("DB_EmailAlertConnectionString1").ToString()
-
-
EmailAlertDataSource.InsertCommandType = SqlDataSourceCommandType.Text
-
EmailAlertDataSource.InsertCommand = "INSERT INTO Table_Emails (EmailAccount, EmailAccountDateEntered, EmailCategory) VALUES (@EmailAccount, @EmailAccountDateEntered, @EmailCategory)"
-
EmailAlertDataSource.InsertParameters.Add("EmailAccount", tbemail.Text) 'HOW TO CHECK THIS EMAIL EXISTS IN DATABASE??
-
EmailAlertDataSource.InsertParameters.Add("EmailAccountDateEntered", DateTime.Now.ToString("f", New CultureInfo("en-GB")))
-
-
Dim MyItem As ListItem
-
Dim catSelected As String = ""
-
Dim catSelected1 As String = ""
-
'Dim r As Integer
-
For Each MyItem In CheckBoxList1.Items
-
If MyItem.Selected = True Then
-
catSelected = catSelected & MyItem.Text & ","
-
Dim i As Integer = Len(catSelected)
-
catSelected1 = Mid(catSelected, 1, i - 1)
-
'lblMessage.Text = catSelected1
-
End If
-
Next
-
-
EmailAlertDataSource.InsertParameters.Add("EmailCategory", catSelected1)
-
-
Dim rowsAffected As Integer = 0
-
-
Try
-
-
rowsAffected = EmailAlertDataSource.Insert()
-
-
Catch ex As Exception
-
-
-
'Response.Write("<p>strTime:" & strTime)
-
lblError.Text = "An error has occured/"
-
lblError.Text += ex.Message()
-
-
-
'TODO: To create this page
-
'Server.Transfer("email_problem_new.aspx")
-
-
Finally
-
-
EmailAlertDataSource = Nothing
-
-
End Try
-
-
If rowsAffected <> 1 Then
-
-
'Server.Transfer("email_problem_new.aspx")
-
-
Else
-
-
'Server.Transfer("email_confirm_new.aspx")
-
-
End If
-
you can check for the record with IfExists keyword in SQL before inserting if you are using sql-server as your database
syntax would be like.... IfExists(SELECT email_id FROM myTable WHERE email_id=2)
Hi,
I suggest you to make that column as Primary key. So its through Exception catch tht one and do your action
Sign in to post your reply or Sign up for a free account.
Similar topics
by: g_chime |
last post by:
How can I make MySQL reject duplicate rows when inserting?
The table is quite large: 100+ rows and millions of rows.
MySQL doesn't allow me to create a UNIQUE INDEX for all the rows (16
rows...
|
by: planetthoughtful |
last post by:
Hi All,
I have a C# ASP.NET page that submits back to itself to insert details
from a form into a database table. When / if the user refreshes the
page (and gets the standard warning that POST...
|
by: mindwarp |
last post by:
Hi,
When a user submits / posts data my php script Inserts data into my
database.
If they refresh the script or click back and click submit again I get
duplicate record.
Is there an easy...
|
by: FangQ |
last post by:
hi
I am very new to mysql. I have a question about using the "on duplicate
update" clause with insert command.
my table "data" has two columns, field1 and field2, where field1 is the
index...
|
by: Iona |
last post by:
Hi Allan,
I'm using a nifty piece of code you put on here some time back to do a
duplicate entry check as below. I'm using to check for duplicate names.
However I am getting an error message on...
|
by: Alan Little |
last post by:
I have affiliates submitting batches of anywhere from 10 to several
hundred orders. Each order in the batch must include an order ID,
originated by the affiliate, which must be unique across all...
|
by: ebindia0041 |
last post by:
This is like the bug from hell. It is kind of hard to explain, so
please bear with me.
Background Info: SQL Server 7.0, Asp.net 1.1 with c#
I'm inserting simple records into a table. But one...
|
by: richardkreidl |
last post by:
I'm trying to check for duplicates before I do an INSERT into the
Access database table. I basically want to alert the user if the
'ProjectName' and the 'MileStones' are already in the table..
...
|
by: Ranma13 |
last post by:
Hello, I have a duplicate record check written in VB for a check in/check out database. Here's the pseudocode, written for the BeforeUpdate property on the form:
If DCount(search for records with...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| |