Click here to Skip to main content
11,577,710 members (61,928 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL VB.NET insert
This code i create it to insert Valus in sql Database but this Code insert Duplicate Record in the same time

I do not know why this Duplication



        connectionString = ConfigurationManager.ConnectionStrings("conString").ToString
        con = New SqlConnection(connectionString)
        con.Open()
        cmd = New SqlCommand("INSERT INTO Msg (ID,MsgName,MgsPhone,MsgAdd,Msgmail,Msgcomm,msgdate,Msgtime,latitude,longitude)VALUES ( '" + Request.QueryString("ID") + "', '" & TxtName.Text & "', '" & TxtPhone.Text & "', '" & TxtAdd.Text & "', '" & TxtMail.Text & "' , '" & Txtcomm.Text & "' , '" & System.DateTime.Now.ToString((" yyyy-MM-dd")) & "','" & System.DateTime.Now.ToShortTimeString() & "', '" & latitude & "', '" & longitude & "')", con)
        cmd.ExecuteNonQuery()
        con.Close()
        Response.Redirect(Request.Url.AbsolutePath + "?status=1", False)
Posted 22-Apr-13 21:57pm
Comments
Prasad Khandekar at 23-Apr-13 4:02am
   
Insufficient information. Your page might be getting posted twice. Your table may not have a primary key.
hany1002 at 23-Apr-13 4:22am
   
First Column In my table

MsgID int Unchecked
vaibhav10Dec1987 at 23-Apr-13 4:54am
   
can you provide me in which event you wrote that code...
hany1002 at 23-Apr-13 4:55am
   
Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
hany1002 at 23-Apr-13 5:05am
   
i found the problem in this html line

<asp:Button ID="btnSave" runat="server" CssClass="bigButton2" style="color: #FFFFFF; font-weight: 700; background-color: #333333" Text="Send" Width="180px" Height="38px" onclick="btnSave_Click" />


in this code (onclick="btnSave_Click" />)

why this problem according ???

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

i found the problem in this html line
 
         <asp:Button ID="btnSave" runat="server" CssClass="bigButton2" style="color: #FFFFFF; font-weight: 700; background-color: #333333" Text="Send" Width="180px" Height="38px" onclick="btnSave_Click" />
 

in this code  (onclick="btnSave_Click" />
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Peter Leow 180
1 Richard MacCutchan 175
2 DamithSL 150
3 OriginalGriff 135
4 Afzaal Ahmad Zeeshan 95
0 OriginalGriff 830
1 Sergey Alexandrovich Kryukov 701
2 Abhinav S 573
3 F-ES Sitecore 420
4 Dave Kreskowiak 374


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100