Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 8th, 2008, 06:12 AM
Authorized User
 
Join Date: Jun 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old June 8th, 2008, 09:50 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #3 (permalink)  
Old June 8th, 2008, 10:09 AM
Authorized User
 
Join Date: Jun 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #4 (permalink)  
Old June 8th, 2008, 10:39 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Yes, that part was already clear. But why is it not working? Do you get an error?

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.
Reply With Quote
  #5 (permalink)  
Old June 8th, 2008, 10:52 AM
Authorized User
 
Join Date: Jun 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Yes, that part was already clear. But why is it not working? Do you get an error?

Imar

i am not getting any error...
n also , i am not getting those display messages...

i am new to this asp.net 2.0 .. i donnow whether my coding is correct r not..

---------------------------------------
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
Reply With Quote
  #6 (permalink)  
Old June 8th, 2008, 11:01 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #7 (permalink)  
Old June 8th, 2008, 11:24 AM
Authorized User
 
Join Date: Jun 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #8 (permalink)  
Old June 8th, 2008, 11:34 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #9 (permalink)  
Old June 8th, 2008, 11:59 AM
Authorized User
 
Join Date: Jun 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default


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
Reply With Quote
  #10 (permalink)  
Old June 8th, 2008, 12:14 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoid enter data from keyboard into combobox mona_upm84 Excel VBA 1 September 5th, 2008 01:26 AM
how to avoid edit of inserted data in Excel? kotaiah Excel VBA 3 September 14th, 2006 01:49 AM
loop problem - duplication crmpicco Classic ASP Basics 1 March 18th, 2005 11:19 AM
show one record if there are duplication yylee Access 1 January 9th, 2005 05:57 AM
Duplication problem mateenmohd SQL Server 2000 0 October 14th, 2003 02:02 AM



All times are GMT -4. The time now is 04:18 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.