A
alan
I've use VB.NET+Access to write build a simple POS application. For
example i got two computer, comp A and comp B. Which comp A share a
Access db file through the network. When open a new bill, the
application will get the latest bill Id from the Access db file and
then update the bill Id=bill Id+1. Right now comp A have already get
the bill Id and update the bill Id=bill iD+1. 2 sec later, comp B also
try to get the bill Id. There is no problem when it get the bill Id,
but there is an error when it try to update the bill Id. Why?
The code that I get the bill Id and update the bill Id is as follow:
'**********************
'Get the Bill Id
'*********************
Dim transMain As OleDbTransaction
cmd = New OleDbCommand
cmd.CommandText = "select next_order_id from [shop]"
Try
cnn = New OleDbConnection(conStr)
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cnn.Open()
transMain = cnn.BeginTransaction()
cmd.Transaction = transMain
custOrderid = cmd.ExecuteScalar()
transMain.Commit()
cnn.Close()
Catch exp As Exception
transMain.Rollback()
MsgBox("1")
MsgBox(exp.Message)
Catch err As OleDbException
transMain.Rollback()
MsgBox("2")
MsgBox(err.Message)
End Try
'******************
Update the Bill Id
'******************
Dim transMain As OleDbTransaction
Try
cmd.CommandText = "Update shop set next_order_id=" & custOrderid +
1 & " "
cnn = New OleDbConnection(conStr)
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
MsgBox(cnn.State)
cnn.Open()
MsgBox(cnn.State)
transMain = cnn.BeginTransaction()
cmd.Transaction = transMain
cmd.ExecuteScalar()
transMain.Commit()
cnn.Close()
cnn.Dispose()
Catch exp As Exception
MsgBox("5")
MsgBox(exp.Message)
transMain.Rollback()
Catch err As OleDbException
MsgBox("6")
MsgBox(err.Message)
transMain.Rollback()
End Try
example i got two computer, comp A and comp B. Which comp A share a
Access db file through the network. When open a new bill, the
application will get the latest bill Id from the Access db file and
then update the bill Id=bill Id+1. Right now comp A have already get
the bill Id and update the bill Id=bill iD+1. 2 sec later, comp B also
try to get the bill Id. There is no problem when it get the bill Id,
but there is an error when it try to update the bill Id. Why?
The code that I get the bill Id and update the bill Id is as follow:
'**********************
'Get the Bill Id
'*********************
Dim transMain As OleDbTransaction
cmd = New OleDbCommand
cmd.CommandText = "select next_order_id from [shop]"
Try
cnn = New OleDbConnection(conStr)
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cnn.Open()
transMain = cnn.BeginTransaction()
cmd.Transaction = transMain
custOrderid = cmd.ExecuteScalar()
transMain.Commit()
cnn.Close()
Catch exp As Exception
transMain.Rollback()
MsgBox("1")
MsgBox(exp.Message)
Catch err As OleDbException
transMain.Rollback()
MsgBox("2")
MsgBox(err.Message)
End Try
'******************
Update the Bill Id
'******************
Dim transMain As OleDbTransaction
Try
cmd.CommandText = "Update shop set next_order_id=" & custOrderid +
1 & " "
cnn = New OleDbConnection(conStr)
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
MsgBox(cnn.State)
cnn.Open()
MsgBox(cnn.State)
transMain = cnn.BeginTransaction()
cmd.Transaction = transMain
cmd.ExecuteScalar()
transMain.Commit()
cnn.Close()
cnn.Dispose()
Catch exp As Exception
MsgBox("5")
MsgBox(exp.Message)
transMain.Rollback()
Catch err As OleDbException
MsgBox("6")
MsgBox(err.Message)
transMain.Rollback()
End Try