 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 8th, 2008, 06:12 AM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how to avoid duplication of data
hi,
my problem is that, before inserting a value to a table , i am just checking whether it is available or not in the table to avoid duplication.
in my table , i got 6 fields..they are.. surname,firstnname,email1,username,.....
i would like to insert the value into this table , before inserting it i would like to check it as i said you before...i am just checking with the email1 field (it can be the only unique field in my table..)
jst help me out to sort this issue for me plz...i do have posted the code with this mail.. when i execute the program , i could not able to get any result...just check whether my coding is correct r not, bit weak in coding..thnx for ur help
waiting for your reply dudes...
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'TextBox9.Text = "yes"
Dim conPubs As OleDbConnection
Dim cmdSelect As OleDbCommand
Dim strSelect As String
Dim dtrAuthors As OleDbDataReader
conPubs = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source=C:\Users\navibingo20\Documents\Visual Studio 2005\WebSites\jupitel site\callingcard.mdb")
strSelect = "Select count(*) From maindata1 WHERE email1='" & txtEmail.Text & "';"
cmdSelect = New OleDbCommand(strSelect, conPubs)
'cmdSelect.Parameters.Add("@email1", txtEmail.Text)
'cmdSelect.Parameters.Add("@acct", TextBox2.Text)
conPubs.Open()
If cmdSelect.ExecuteScalar() <> 0 Then
Label2.Visible = True
TextBox9.Text = "yes"
Response.Write("yes")Response.Redirect("sample2.as px")
Else
'Label2.Visible = True
TextBox9.Text = "no"
Response.Write("no")
'Response.Redirect("sample2.aspx")
End If
' dtrAuthors = cmdSelect.ExecuteReader()
' dtrAuthors.Close()
conPubs.Close()
End Sub
trainee
__________________
trainee
|
|

June 8th, 2008, 09:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
And what exactly is the problem? I don't hope you expect us to copy this code, run it, recreate the database and then see what happens?
How about you describe the behavior, and what it is you want the code to do? You may also want to explain if "yes" means "found" or "go ahead and create the account".
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
|
|

June 8th, 2008, 10:09 AM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by Imar
And what exactly is the problem? I don't hope you expect us to copy this code, run it, recreate the database and then see what happens?
How about you describe the behavior, and what it is you want the code to do? You may also want to explain if "yes" means "found" or "go ahead and create the account".
Imar
hi imar,
i need to insert the value in to the table and also trying to avoid duplication of data.
i am checking whether the emailid is already in the table or not. if the table contains the same email id , i dont want to insert the data into the table..else i need to insert it..
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
|
trainee
|
|

June 8th, 2008, 10:52 AM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
|

June 8th, 2008, 11:01 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
First of all, can you please not quote the entire message? Simply hitting the Reply button should be fine...
Secondly: I assume that you think the code is not working right and not doing what it is supposed to do, right? Then maybe you can describe what it is supposed to do (other than check the user's e-mail as you already described that part), and what it is actually doing? E.g. describe the difference between expected and actual behavior. Describe what you see, what pages get loaded and so on.
If you are not explaining to us what the problem is, how do you expect us to solve it for you? Very confusing..... ;)
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
|
|

June 8th, 2008, 11:24 AM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi ,
sorry for tht imar..
i am retrieving the username , email id from sql server table and displaying it in a textbox in the welcome page. using that emailid field , i am retrieving the surname and first name from other table and displaying it in the welcome page-(user details).
now i want to insert these values (like, surname, firstname,email,username....) in to a new table (access).
if the user log's in for the first time..it works fine and if he log in second time , the same data will be entered in the table.. i am trying to avoid this duplication.
username,email,surname--all these fields are retrieved in sub page_load function.
trainee
|
|

June 8th, 2008, 11:34 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Pffff, yes I understand all of that. However, you need to provide lots more information. Just like Joe, I am not allowed to use my mind reading skills here on this forum. Additionally, I don 't have access to the rest of your code so I can't help you with your problem unless you provide more information.
The code you posted is just a simple check for a user name. Nowhere do I see any code to insert a user in the database. So, the current code can't be the problem all by itself.
So, once more, please provide relevant information. Show us the relevant code, tells us what fires when, tell us where you use the code that you posted and what code is responsible for inserting the user, tell us the relevant information that the debugger provides at important stages (e.g. right after the user check for example) etc etc etc.
Please realize that I can't look inside your head. Just reread your own posts and see if you can understand that it is very incomplete information for an outsider that doesn't know what you are doing.
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
|
|

June 8th, 2008, 11:59 AM
|
|
Authorized User
|
|
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i do have attached the entire code with this post..
Sub page_load()
TextBox1.Text = Profile.UserName
'TextBox4.Text = Profile.Email
If String.IsNullOrEmpty(TextBox1.Text) Then
' if there is not username passed via query string ,
' we hide user details panel
pnlEmpty.Visible = True
PnlUserDetails.Visible = False
Else
'' if here is a username passed via qiery string , we show the details region and hide the Empty panel
pnlEmpty.Visible = False
PnlUserDetails.Visible = True
'' get the user details based on the passed userName
Dim MUser As MembershipUser = Membership.GetUser(TextBox1.Text)
txtUserName.Text = MUser.UserName
txtPassword.Text = MUser.LastLoginDate
txtEmail.Text = MUser.Email
txtCreationDate.Text = MUser.CreationDate
chkIsApproved.Checked = MUser.IsApproved
chkisOnline.Checked = MUser.IsOnline
Dim conPubs As OleDbConnection
Dim cmdSelect As OleDbCommand
Dim strSelect As String
Dim dtrAuthors As OleDbDataReader
conPubs = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source=C:\Users\Deva\Documents\Visual Studio 2005\WebSites\jupitel site\callingcard.mdb")
strSelect = " select accountnumber from custdetails where email=@email"
cmdSelect = New OleDbCommand(strSelect, conPubs)
conPubs.Open()
cmdSelect.Parameters.Add("@email", txtEmail.Text)
dtrAuthors = cmdSelect.ExecuteReader()
dtrAuthors.Read()
TextBox2.Text = dtrAuthors.GetString(0)
dtrAuthors.Close()
conPubs.Close()
// retrieving the accountnumber and storing it in texbox2.text
// similarly i am doing it for surname and firstname and storing it in textbox7 and textbox8 respectively.
End If
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim conPubs As OleDbConnection
Dim cmdSelect As OleDbCommand
Dim strSelect As String
Dim dtrAuthors As OleDbDataReader
conPubs = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source=C:\Users\Deva\Documents\Visual Studio 2005\WebSites\jupitel site\callingcard.mdb")
strSelect = "Select count(*) From maindata1 WHERE email1='" & txtEmail.Text & "';"
cmdSelect = New OleDbCommand(strSelect, conPubs)
'cmdSelect.Parameters.Add("@email1", txtEmail.Text)
'cmdSelect.Parameters.Add("@acct", TextBox2.Text)
conPubs.Open()
// just checking whether the email id is already present in the table or not..
If cmdSelect.ExecuteScalar() <> 0 Then
Label2.Visible = True
TextBox9.Text = "yes"
Response.Write("yes")
//i am just trying to execute this alone, i could not able to see the display messages in the textbox9..in both the cases..
//just trying to paste the insert query command here..
Response.Redirect("sample2.aspx")
Else
'Label2.Visible = True
TextBox9.Text = "no"
Response.Write("no")
'Response.Redirect("sample2.aspx")
End If
'Dim conPubs11 As OleDbConnection
'Dim cmdInsert11 As OleDbCommand
'Dim strInsert11 As String
'conPubs11 = New OleDbConnection'("PROVIDER=Microsoft.Jet.OLEDB.4.0 ;DATA Source=C:\Users\Deva\Documents\Visual Studio 2005\WebSites\jupitel site\callingcard.mdb")
'strInsert11 = "insert into maindata1 (accountnumber, surname, username, email1, fname )values ( @acct, @sn, @user1, @email, @fn)"
'cmdInsert11 = New OleDbCommand(strInsert11, conPubs11)
'cmdInsert11.Parameters.Add("@acct", TextBox2.Text)
'cmdInsert11.Parameters.Add("@sn", TextBox7.Text)
'cmdInsert11.Parameters.Add("@user1", TextBox1.Text)
'cmdInsert11.Parameters.Add("@email", txtEmail.Text)
'cmdInsert11.Parameters.Add("@fn", TextBox8.Text)
'conPubs11.Open()
'cmdInsert11.ExecuteNonQuery()
'conPubs11.Close()
'Response.Write("its checking username")
// in this button click i am just inserting the values in to the table..
End Sub
Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As System.EventArgs)
'TextBox9.Text = "yes"
'dtrAuthors = cmdSelect.ExecuteReader()
'dtrAuthors.Close()
'conPubs.Close()
End Sub
trainee
|
|

June 8th, 2008, 12:14 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Oh come on! Are you doing this on purpose that make fun of us? Pffff.
This is my last attempt before I give up. You have to help me help you, or we won't get anywhere.
You are not answering my questions; you are not providing relevant information, you post code that doesn't have anything to do without your problem. If you can't provide relevant info, I can't help you. You are not even explaining what button you press, what the flow of the page is and so on. So how come you expect me to see what the problem is and help you? Please, again, reread everything you have posted, think of someone who doesn't know what it is all about. You'll see it's not enough.
The code you posted can't be the problem. All the code that inserts the user is commented out so it cannot cause duplicate records. Remember, I only see this code here on P2P, not running in an IDE.
Must ... go .... now..... very ..... tired.... of .... this.....
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
|
|
 |