title: SQL transaction statement in vb.net
body: <p>I'm making a project that is linked to Microsoft SQLServer, used to enter, remove, edit data about customers and orders. The full system works, however I've been advised to use transactions rather than regular SQL statements to add/remove/edit data etc.</p>
  
  <p>The trouble is, I've not used these before and from my research over the last few hours, I can't work out how to even begin them.</p>
  
  <p>Can anybody advise me how to turn the following code into a transaction?</p>
  
  <pre><code>    Public Shared Function SaveNewPerson(ByVal firstName As String, lastName As String, ByVal age As Integer, ByVal postcode As String, m_cn As OleDbConnection)
  
      Dim Dc As New OleDbCommand
      Dc.Connection = m_cn
  
      m_cn.Open()
  
      Dc.CommandText = "INSERT INTO tblPerson([firstName], [lastName], [age], [postcode]) VALUES('" &amp; firstName &amp; "', '" &amp; lastName &amp; "', '" &amp; age &amp; "', '" &amp; postcode &amp; "')"
  
      Dc.ExecuteNonQuery()
  
      Dim personID As Integer
  
      Dc.CommandText = "SELECT @@IDENTITY"
      Dc.CommandType = CommandType.Text
      personID = CType(Dc.ExecuteScalar(), Integer)
  
      m_cn.Close()
  
  End Function
  </code></pre>