title: want to update record if exists and insert if not exists
body: <p>want to update record if exists and insert if not exists into vsolv_trn_tsalesregdump Is tsalesregdump_name is unique in table vsolv_trn_tsalesregdump</p>
  
  <p>when i click check box that particular row should be check on other table and how to use it for loop in form loop i can use the "tsalesdump_date,tsalesdump_name,executivename_executive" this three if the value is same its go to update and otherwise its not to same its move on insert how can i write it can any 1help me</p>
  
  <p>if i have use two table one temp and other 1 is orginal\   temp table =vsolv_tmp_tsalesdump   orginal table=vsolv_trn_tsalesregdump.</p>
  
  <p>if already i hav save the data in orginal table,again if i hav assing data for temp table and view in radgrid if select and submit the button its go to check on orginal table if the value is already there its update it otherwise insert   how can use it</p>
  
  <pre><code>Protected Sub btn_Submit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btn_Submit.Click
      lblerrmsg.Text = ""
      Dim chk As CheckBox
      Dim lbtn As LinkButton
      Dim Res As Long
      Dim lobjrow As DataRow
      Dim lObjErrTable As New DataTable
      Dim a As Integer = 0
      Dim dtcarbooking As New DataTable
      Dim dtDumpBooking As New DataTable
      Dim lsRefid As String = String.Empty
      Dim dtdumpsample As New DataTable
      Dim name As String = String.Empty
  
      If Check_Validation() = True Then
          Exit Sub
      End If
      Gobjdbconn.OpenConn()
  
      lObjErrTable = Error_TabelFill()
  
      For i As Integer = 0 To GVUpload.Items.Count - 1
          chk = GVUpload.Items(i).FindControl("chkupload")
          If chk.Checked = True Then
  
                  lsRefid = GVUpload.Items(i).GetDataKeyValue("tsalesdump_gid").ToString()
  
  
              MsSql = ""
              MsSql &amp;= "Select tsalesdump_gid,tsalesdump_date,tsalesdump_name,executivename_executive,tsalesdump_vch_no,tsalesdump_debit,tsalesdump_credit"
              MsSql &amp;= " from vsolv_tmp_tsalesdump as a"
              MsSql &amp;= " left join vsolv_trn_executivename as b on a.tsalesdump_name = b.executivename_particulars"
              MsSql &amp;= " where tsalesdump_gid = '" &amp; lsRefid &amp; "' and tsalesdump_isremoved = 'N'"
              dtDumpBooking = Gobjdbconn.GetDataTable(MsSql)
  
  
              MsSql = ""
              MsSql &amp;= "Insert into vsolv_trn_tsalesregdump(tsalesregdump_date,tsalesregdump_name,tsalesregdump_executive,tsalesregdump_vch_no"
              MsSql &amp;= " ,tsalesregdump_debit,tsalesregdump_credit,tsalesregdump_importby)"
              MsSql &amp;= " Values ('" &amp; Format(CDate(dtDumpBooking.Rows(0).Item("tsalesdump_date")), "yyyy-MMM-dd").ToString() &amp; "'"
              MsSql &amp;= ",'" &amp; dtDumpBooking.Rows(0).Item("tsalesdump_name").ToString() &amp; "'"
              MsSql &amp;= ",'" &amp; dtDumpBooking.Rows(0).Item("executivename_executive").ToString() &amp; "'"
              MsSql &amp;= " ,'" &amp; dtDumpBooking.Rows(0).Item("tsalesdump_vch_no").ToString() &amp; "'"
              MsSql &amp;= " ,'" &amp; dtDumpBooking.Rows(0).Item("tsalesdump_debit").ToString() &amp; "','" &amp; dtDumpBooking.Rows(0).Item("tsalesdump_credit").ToString() &amp; "','SIVA')"
  
              MnResult = Gobjdbconn.ExecuteNonQuerySQL(MsSql)
  
              If MnResult = 1 Then
                  MsSql = ""
                  MsSql &amp;= " Delete from vsolv_tmp_tsalesdump where tsalesdump_gid = '" &amp; lsRefid &amp; "'"
                  Gobjdbconn.ExecuteNonQuerySQL(MsSql)
              Else
                  lobjrow = lObjErrTable.NewRow()
                  a = a + 1
                  lobjrow("Sno") = a
                  lobjrow("Booking Ref No") = dtcarbooking.Rows(0).Item("tsalesregdump_name").ToString
                  lobjrow("Description") = "Duplicate Record"
                  lObjErrTable.Rows.Add(lobjrow)
              End If
  
          End If
      Next
  
  
      POPSummary()
  
      If Not lObjErrTable Is Nothing Then
          If lObjErrTable.Rows.Count &gt; 0 Then
              Call Pop_Data(lObjErrTable)
          End If
      End If
  
  End Sub
  </code></pre>