Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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



VB
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
Comments
Prasad Khandekar 23-Apr-13 4:02am    
Insufficient information. Your page might be getting posted twice. Your table may not have a primary key.
hany1002 23-Apr-13 4:22am    
First Column In my table

MsgID int Unchecked
vaibhav10Dec1987 23-Apr-13 4:54am    
can you provide me in which event you wrote that code...
hany1002 23-Apr-13 4:55am    
Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
hany1002 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

XML
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" />)
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900