View Single Post
  #3 (permalink)  
Old May 15th, 2008, 07:11 AM
vsc33 vsc33 is offline
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply. Here is the code. Waiting for your suggestion.

con = connect()
con.Open()

'transaction begins here-------
trans = con.BeginTransaction()

Try

'Data is inserted into mastertable---------

cmd = New SqlClient.SqlCommand("INSERT INTO mastertable(mbno,mbdate,mbamount,mbcperson) VALUES(" & counter_bill_no & ",'" & server_date & "'," & billvalue & "," & countercode & ")", con, trans)
cmd.ExecuteNonQuery()

cmd = New SqlClient.SqlCommand("select mbid from mastertable WHERE mbno=" & counter_bill_no & " and mbcperson=" & countercode & " ", con, trans)
mb_id = cmd.ExecuteScalar

'Data inserted into detailtable-----------

i = 0
For i = 0 To row_no - 1
selling_rate = DataGridView1.Item(2, i).Value
If selling_rate <> 0 Then
cmd = New SqlClient.SqlCommand("INSERT INTO detailtable(dbno,dbdate,dbicode,biquantity,dbamoun t) VALUES(" & mb_id & ",'" & server_date & "'," & DataGridView1.Item(4, i).Value & "," & DataGridView1.Item(1, i).Value & "," & DataGridView1.Item(3, i).Value & ")", con, trans)
cmd.ExecuteNonQuery()
End If
Next i

'Data commited--------

trans.Commit()

Catch ex As Exception

trans.Rollback()
MsgBox("Bill could not be generated, Please try again.")

End Try

con.Close()

Reply With Quote