error while updating same records

Posted by Priti2010 under VB.NET on 8/10/2011 | Points: 10 | Views : 1177 | Status : [Member] | Replies : 2
Dim str As String
str = String.Empty
Dim Service_Name As String
Dim colindex As Integer = 1
Service_Name = DirectCast(GridviewOdin.Rows(e.RowIndex).FindControl("Service_Name"), TextBox).Text
str = "SELECT COUNT(*) FROM tbl_Service WHERE LTRIM(RTRIM(Service_Name))='" & Service_Name & "'"
mycommand = New SqlCommand(str, myconnection)
Dim mCount As Integer = mycommand.ExecuteScalar()
'myconnection.Close()

If mCount = 0 Then
update procedure
else
MsgBox("Duplicate Service Found", MsgBoxStyle.OkOnly, "")
end if
This above is my query i cant update the grid with the same record present in the grid but if i update new records it will check and update but existing records cannot be update in the same row
how can i solve this error

Thanks & Regards
Priti



Responses

Posted by: Hmanjarawala on: 8/10/2011 [Member] Bronze | Points: 25

Up
0
Down
Hello Priti,

i think if you are trying to update record base on service name then your mcount won't come 0 caz you are updating record means that record is exist.....so i think you have to check mcount = 1 as condition

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Priti2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Priti2010 on: 8/11/2011 [Member] Starter | Points: 25

Up
0
Down
ya right but if i take mcount=1 then the exiting record get updated but if any new entry is made in the same update command then my mcount =0 which gives me and error. how can i solve this error that while update, duplicate records should be check for new value and also existing records

Thanks & Regards
Priti

Priti2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response