473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Can't save data to SQL Server

Hi Everyone,
I have a simple page right now to save an PO info to the server. I get the
following error:
"ExecuteNonQuery requires the command to have a transaction when the
connection assigned to the command is in a pending local transaction. The
Transaction property of the command has not been initialized."
Theres no error number. I'm using the following code:
Protected Sub cmdSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdSave.Click
Dim mCommand As SqlCommand
Dim cnSQL as SqlConnection
Dim rtn as Integer
Dim result as Boolean = True
Dim SaveTrans As SqlTransaction
try
cmdAddnew.Enabled = True
cnSQL = OpenConnection()
SaveTrans = cnSQL.BeginTransaction
mCommand = New SqlCommand
mCommand.CommandType = CommandType.StoredProcedure
mCommand.Connection = cnSQL
mCommand.CommandText = "Admin_AddPO"
mCommand.Parameters.add("@ProgramId", SqlDbType.Int ).Value =
cmbPrograms.SelectedValue
mCommand.Parameters.add("@OrderDate", SqlDbType.DateTime ).Value =
format(Now(), "mm/dd/yyyy")
mCommand.Parameters.add("@VendorName", SqlDbType.VarChar , 250 ).Value =
txtVendorName.Text
mCommand.Parameters.add("@ReturnValue", SqlDbType.int).Direction =
ParameterDirection.ReturnValue
mCommand.ExecuteNonQuery
rtn = mCommand.Parameters("@ReturnValue").Value.ToString

mCommand = New SqlCommand
mCommand.CommandType = CommandType.StoredProcedure
mCommand.CommandText = "Admin_AddPOItems"
mCommand.Parameters.add("@POrderId", SqlDbType.Int ).Value = rtn
mCommand.Parameters.add("@CatalogeId", SqlDbType.VarChar , 20 ).Value =
txtCatalogID.Text
mCommand.Parameters.add("@ItemDescription", SqlDbType.VarChar , 250
).Value = txtDescription.Text
mCommand.Parameters.add("@Qty", SqlDbType.Int ).Value = txtQty.Text
mCommand.Parameters.add("@UnitPrice", SqlDbType.Money ).Value =
txtUnitPrice.Text
mCommand.Parameters.add("@Page", SqlDbType.VarChar , 10 ).Value =
txtPage.Text
mCommand.ExecuteNonQuery

Catch ex As Exception
msgbox(ex.Message )
result = False
finally
if result then
SaveTrans.Commit
SqlDataPOs.DataBind
else
SaveTrans.Rollback
End If
cnSQL.Dispose
mCommand.Dispose
SaveTrans.Dispose
End Try

End Sub

Public Function OpenConnection() as SqlConnection
try
NetCon = New SqlConnection
With NetCon
.ConnectionString = "packet size=4096;integrated security=SSPI;data
source=Backupsvr\bkupexec;persist security info=False;initial
catalog=PurchaseOrders"
.Open()
End With
return NetCon
Catch ex As Exception
msgbox(ex.Message )
return nothing
End Try
End Function

I hope someone can help. Thanks for any info that you can provide.
Michael

Mar 17 '06 #1
1 1336
Sorry about this, I found my problem. I forgot to assign the transaction to
the command object
mCommand.Transation = SaveTrans
Thanks for the look.
Michael

"Michael" wrote:
Hi Everyone,
I have a simple page right now to save an PO info to the server. I get the
following error:
"ExecuteNonQuery requires the command to have a transaction when the
connection assigned to the command is in a pending local transaction. The
Transaction property of the command has not been initialized."
Theres no error number. I'm using the following code:
Protected Sub cmdSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdSave.Click
Dim mCommand As SqlCommand
Dim cnSQL as SqlConnection
Dim rtn as Integer
Dim result as Boolean = True
Dim SaveTrans As SqlTransaction
try
cmdAddnew.Enabled = True
cnSQL = OpenConnection()
SaveTrans = cnSQL.BeginTransaction
mCommand = New SqlCommand
mCommand.CommandType = CommandType.StoredProcedure
mCommand.Connection = cnSQL
mCommand.CommandText = "Admin_AddPO"
mCommand.Parameters.add("@ProgramId", SqlDbType.Int ).Value =
cmbPrograms.SelectedValue
mCommand.Parameters.add("@OrderDate", SqlDbType.DateTime ).Value =
format(Now(), "mm/dd/yyyy")
mCommand.Parameters.add("@VendorName", SqlDbType.VarChar , 250 ).Value =
txtVendorName.Text
mCommand.Parameters.add("@ReturnValue", SqlDbType.int).Direction =
ParameterDirection.ReturnValue
mCommand.ExecuteNonQuery
rtn = mCommand.Parameters("@ReturnValue").Value.ToString

mCommand = New SqlCommand
mCommand.CommandType = CommandType.StoredProcedure
mCommand.CommandText = "Admin_AddPOItems"
mCommand.Parameters.add("@POrderId", SqlDbType.Int ).Value = rtn
mCommand.Parameters.add("@CatalogeId", SqlDbType.VarChar , 20 ).Value =
txtCatalogID.Text
mCommand.Parameters.add("@ItemDescription", SqlDbType.VarChar , 250
).Value = txtDescription.Text
mCommand.Parameters.add("@Qty", SqlDbType.Int ).Value = txtQty.Text
mCommand.Parameters.add("@UnitPrice", SqlDbType.Money ).Value =
txtUnitPrice.Text
mCommand.Parameters.add("@Page", SqlDbType.VarChar , 10 ).Value =
txtPage.Text
mCommand.ExecuteNonQuery

Catch ex As Exception
msgbox(ex.Message )
result = False
finally
if result then
SaveTrans.Commit
SqlDataPOs.DataBind
else
SaveTrans.Rollback
End If
cnSQL.Dispose
mCommand.Dispose
SaveTrans.Dispose
End Try

End Sub

Public Function OpenConnection() as SqlConnection
try
NetCon = New SqlConnection
With NetCon
.ConnectionString = "packet size=4096;integrated security=SSPI;data
source=Backupsvr\bkupexec;persist security info=False;initial
catalog=PurchaseOrders"
.Open()
End With
return NetCon
Catch ex As Exception
msgbox(ex.Message )
return nothing
End Try
End Function

I hope someone can help. Thanks for any info that you can provide.
Michael

Mar 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ben Turner | last post by:
I'm querying a web service to get some global weather data (http://www.webservicex.net/globalweather.asmx?WSDL) which works really well, however I'm getting stuck on the returned data for the...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
47
by: Lauren Wilson | last post by:
One more try. After ransacking the Desktop AND Enterprise edition of Ken Getz Dev Handbooks on Access 2002, I STILL don't know if it is or is not possible to link a client side MDE with a WEB...
0
Boxcar74
by: Boxcar74 | last post by:
Hi Everybody!!! I have an Issue. I have an Excel file that queries an Access db. I’m trying to have it so I don’t have to keep updating it manually everyday and save it to a network drive...
2
by: phpnoob | last post by:
I have a php script that processes a form and then posts the user input to a data file on the server in a comma delimited format. For simplicity call the file "data.csv." The script is working...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.