declare @Rate int
-- Insert statements for procedure here
set @Rate = (select prate from M_PRDT where PID=@ppid)
IF EXISTS (SELECT * FROM trans WHERE cid =@pcid and pid=@ppid)
UPDATE trans set pid=@ppid,rate =@Rate WHERE cid =@pcid and pid=@ppid
Else
insert into trans (tid,cid,pid,qty,rate,frmdt,todt)
select @ptid,@pcid,@ppid,@pqty,@Rate,'1/1/1900','1/1/1900'
END
Dim cmd3 As New SqlCommand("usp_update", conn)
cmd3.CommandText = CommandType.StoredProcedure
cmd3.Parameters.AddWithValue("@pcid", CInt(lblid.Text))
cmd3.Parameters.AddWithValue("@ppid", CInt(CHK_PRDT.CheckedItems.Item(i)("pid")))
cmd3.Parameters.AddWithValue("@ptid", maxid1)
cmd3.Parameters.AddWithValue("@pqty", "0")
cmd3.ExecuteNonQuery()