data is inserting twice in database

Posted by hareeshkumarkr-16190 under ASP.NET on 9/10/2012 | Points: 10 | Views : 1247 | Status : [Member] | Replies : 5
hi

i have an issue regarding gridview button click.
when i click button inside a gridview, data is saving in a database twice.
can anyone help regarding this issue.




Responses

Posted by: Naraayanan on: 9/10/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Please post your code.

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

hareeshkumarkr-16190, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: hareeshkumarkr-16190 on: 9/10/2012 [Member] Starter | Points: 25

Up
0
Down
My code :

If e.CommandName = "vmore" Then
Dim index As Integer = Integer.Parse(e.CommandArgument.ToString())
Dim gr As GridViewRow = GridView1.Rows(index)
'Dim btn1 As MultiView = DirectCast(gr.FindControl("MultiView1"), MultiView)
Dim imgbtnsvm As ImageButton = DirectCast(gr.FindControl("vmore"), ImageButton)

Dim lblslno As Label = DirectCast(gr.FindControl("lblslno"), Label)

Call viewdetails(Integer.Parse(lblslno.Text))

End If

Private Sub viewdetails(ByVal sl As Integer)

con.Open()
Dim cmd As SqlCommand = con.CreateCommand
cmd.CommandText = "Home_userrecordhit_spinsert"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@mtid", sl)
cmd.Parameters.AddWithValue("@useremailid", usrid)

cmd.ExecuteNonQuery()

con.Close()

End Sub

hareeshkumarkr-16190, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vasanthmvp on: 9/11/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Could you post your code here. or try by debugging it with break points. so that you can trace the things.

Regards,

Awesome Coding !! :)

hareeshkumarkr-16190, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: hareeshkumarkr-16190 on: 9/11/2012 [Member] Starter | Points: 25

Up
0
Down

HI
@ VASANTH

My code :

If e.CommandName = "vmore" Then
Dim index As Integer = Integer.Parse(e.CommandArgument.ToString())
Dim gr As GridViewRow = GridView1.Rows(index)
'Dim btn1 As MultiView = DirectCast(gr.FindControl("MultiView1"), MultiView)
Dim imgbtnsvm As ImageButton = DirectCast(gr.FindControl("vmore"), ImageButton)

Dim lblslno As Label = DirectCast(gr.FindControl("lblslno"), Label)

Call viewdetails(Integer.Parse(lblslno.Text))

End If

Private Sub viewdetails(ByVal sl As Integer)

con.Open()
Dim cmd As SqlCommand = con.CreateCommand
cmd.CommandText = "Home_userrecordhit_spinsert"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@mtid", sl)
cmd.Parameters.AddWithValue("@useremailid", usrid)

cmd.ExecuteNonQuery()

con.Close()

End Sub

hareeshkumarkr-16190, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 9/11/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi @Hareeshkumar.Kr@Gmail.Com
Check your action method.
i think your action method was called twice.
Or
please share ur page with us.
Or
Try to recreate your page again.

hareeshkumarkr-16190, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response