Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0I need some help.I need some help.
Previous
 
Next
New Post
6/20/2007 9:42 AM
 
I need some help.
I am writing an application in VB .net and have run into problem and need some help. I have a database that stores the evaluation of some clients. The evaluation is done on a cycle basis, each cycle has 7 day and there are 6 cycles. The thing is the days are continuous for example cycle 1 has day one to 7 but cycle 2 begins on day 8 and cycle 3 on day 15 and so on. The problem is I do want duplicate records happening for any individual. Every individual has an id. So how do I prevent duplicate record for anyone happening? For example for person A prevent Cycle 2 evaluation 9 from being entered twice.
This is how I attempted to do this but it’s not working the way I want. I would like a message to popup if that record already exists.
While cycle.Read
 
            If String.Compare(cycle("ID").ToString.ToLower, Me.TextBox1.Text.ToLower) = 0 Then
                'ID number is found
                'Compare CycleNum
                If String.Compare(cycle("CycleNum").ToString, Me.TextBox5.Text) = 0 Then
                    Me.LB2_Message.Text = "This DOR number already exist for this recruit"
                    cycle.Close()
                    Exit Sub
                Else 'Valid ID name and CycleNum
                    'comm.CommandText = "INSERT INTO TEXT_REPORT(ID,FTO,R_Date,Most,Least,Additional,Week,CycleNum) VALUES('" + Me.TextBox1.Text + "','" + Me.TextBox2.Text + "','" + Me.TextBox3.Text + "','" + Me.txtMost.Text.Replace("'", "''") + "','" + Me.txtLeast.Text.Replace("'", "''") + "','" + Me.txtAdd.Text.Replace("'", "''") + "','" + Me.TextBox4.Text + "','" + Me.TextBox5.Text + "')"
                    Session.Add("ID", cycle("ID").ToString)
                    Session.Add("CycleNum", cycle("CycleNum"))
                    Exit Sub
                End If
            End If
        End While
        cycle.Close()
 
New Post
6/21/2007 2:53 AM
 

First off you should really look into using parameterized queries to prevent sql injections, etc...but that aside - rather than looping through the records to check for dups you could:

1. Create a unique index on ID, CycleNum and catch the SQL error, or

2. Run an update query  - on the entered id and cycle number that simply updates id = id where id = id and cyclenum = cyclenum if the updated records is > 0 the record already exists.

On the popup not sure if this is the best way but you could use something like Response.Write("script> Record Exists.') /script>")

 
New Post
6/21/2007 11:58 AM
 

How do I write the update query I am not sure on this one can you help?

Thanks

 
New Post
6/21/2007 2:14 PM
 

Trafmore wrote

How do I write the update query I am not sure on this one can you help? I did it this way. What I missing

comm.CommandText =

"UPDATE TEXT_REPORT SET IBM ='" + TextBox1.Text + "',FTO='" + TextBox2.Text + "',R_Date='" + TextBox3.Text + "',Most='" + txtMost.Text.Replace("'", "''") + "',Least='" + txtLeast.Text.Replace("'", "''") + "',Additional='" + txtAdd.Text.Replace("'", "''") + "',Week='" + TextBox4.Text + "',DORNum='" + TextBox5.Text + "'Where IBM='" + TextBox1.Text + "'And DORNum='" + TextBox5.Text + "'"

 

Thanks

 
New Post
6/21/2007 11:05 PM
 

It looks like your syntax is correct (or close).  What you may be missing is the how to use it.  You need to use:

Comm.ExecuteNonQuery() 

This function returns an integer indicating the number of records effected.  So if you run an update statement using your keys in the where clause and Comm.ExecuteNonQuery() returns 0 then you need to insert the record.

Again, I recommend searching the net for "SQL Injections" and "Parameterized Queries" - Using parameterized queries will protect you against SQL injections and clean up/simplify your command concatenation.

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0I need some help.I need some help.


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out