In this post I will show you how to perform SQL command operation using ExecuteStoreCommand with Entity Frameworks

Try
   Using ctx = New in4MaticEntities(SetConnectionString())

      Dim rows As Integer

      rows = ctx.ExecuteStoreCommand("UPDATE MYTABLE SET CUSTOMER =0 WHERE CUSTOMER=NULL")
      debug.print("Alterated rows: " & If(row > 0, row.ToString, "nothing") 
      
      rows =ctx.ExecuteStoreCommand("DELETE FROM MYTABLE WHERE CUSTOMER = 10") 
      debug.print("Alterated rows: " & If(row > 0, row.ToString, "nothing") 

      rows =ctx.ExecuteStoreCommand("INSERT INTO MYTABLE (CUSTOMER) VALUES (10)") 
      debug.print("Alterated rows: " & If(row > 0, row.ToString, "nothing") 


   End Using
Catch ex As Exception
     debug.print(ex.ToString)
End Try
Advertisements