Insert into Access DB (loop) - asp.net

I have this code and its coming up with an INSERT INTO statement error...
Its probably something but I have been at it for a while... please help.
'Add items to db'
Function recordOrder()
objDT = Session("Cart")
Dim intCounter As Integer
For intCounter = 0 To objDT.Rows.Count - 1
objDR = objDT.Rows(intCounter)
Dim con2 As New System.Data.OleDb.OleDbConnection
Dim myPath2 As String
myPath2 = Server.MapPath("faraxday.mdb")
con2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath2 & ";"
Dim myCommand2 As New System.Data.OleDb.OleDbCommand
myCommand2.CommandText = "INSERT INTO order(order_date, coupon_id, customer_id, quantity) values('" & System.DateTime.Now & "','" & Int32.Parse(objDR("ID")) & "','" & Int32.Parse(custID) & "','" & Int32.Parse(objDR("quantity")) &"')"
myCommand2.Connection = con2
con2.Open()
myCommand2.ExecuteReader()
con2.Close()
test.Text += "Order ID: " & objDR("ID") & "Order Date: " & System.DateTime.Now & ", Cust ID: " & custID & ", Quantity: " & objDR("quantity") &" "
Next
End Function

I think you are getting an error by not enclosing the Date inside Pound signs. You have to do this in Jet (Access) when using variables not parameters.
VALUES('#" & DateTime.Now.Date & "#',...
I also took the liberty of refactoring this code for you since you are creating a new connection for each record which is bad news. Use a Try Catch Finally block and move all that stuff outside the For Loop (please see below)
Function recordOrder()
objDT = Session("Cart")
Dim intCounter As Integer
Dim con2 As New System.Data.OleDb.OleDbConnection
Dim myPath2 As String
myPath2 = Server.MapPath("faraxday.mdb")
con2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" <-- etc
Dim myCommand2 As New System.Data.OleDb.OleDbCommand
myCommand2.Connection = con2
con2.Open()
Try
For intCounter = 0 To obDT.Rows.Count - 1
objDR = objDT.Rows(intCounter)
myCommand2.CommandText = "INSERT INTO order(order_date,coupon_id,customer_id,quantity)" _
& "VALUES ('#" & System.DateTime.Now.Date & "#','" & Int32.Parse(objDR("ID")) & "','" & Int32.Parse(custID) _
& "','" & Int32.Parse(objDR("quantity")) & "')"
myCommand2.ExecuteReader()
Next
Catch ex As Exception
'handle errors here
Finally
If con2.State = ConnectionState.Open Then
con2.Close()
End If
End Try
End Function
Remember to mark as answered if this helps.

I've sorted it out by removing the single quotes. Thanks everybody to contributed to this.

Related

search query from 2 dates and 2 time

I have 4 Datetimepicker. the 2 datetimepicker is on dateformat(datefrom,dateto) and the other 2 datetimepicker is on Timeformat(timefrom,timeto).
I want to search a table that display only in datagridview that will display only start on Date from and time from to date to and time to... But my code doenst work.
here's my code:
Dim fromto As String = String.Empty
fromto &= "Select * from setplan where endplan >='" & dtimefrom.Text & "'and endplan >='" & dtimeto.Text & "' and [Dateinput] >='" & ddatefrom.Text & "' and [dateinput] <= '" & ddateto.Text & "'"
Dim connection As String = ("provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Administrator\Documents\planning.accdb;Persist Security Info=False;")
Using conn As New OleDb.OleDbConnection(connection)
Using cmd As New OleDb.OleDbCommand(fromto)
With cmd
.Connection = conn
.CommandType = CommandType.Text
.CommandText = fromto
End With
Try
conn.Open()
cmd.ExecuteNonQuery()
Dim da As New OleDb.OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
If ds.Tables.Count > 0 Then
DataGridView1.DataSource = ds.Tables(0)
End If
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Using
End Using
End Sub
You need formatted string expressions for your date/time values:
fromto &= "Select * from setplan where endplan >= #" & ddateto.Value.ToString("yyyy'/'MM'/'dd") & " " & dtimeto.Value.ToString("HH':'mm") & "# and [dateinput] >= #" & ddatefrom.Value.ToString("yyyy'/'MM'/'dd") & " " & dtimefrom.Value.ToString("HH':'mm") & "#"

infinite do until loop within for loop in web app

So my code is going through the various components and creates bundles using the BuildKnittingRecords sub for the various components. My code works well when it creates the bundles for the Case "Sleeve", "Front", "Body", "Back" but when it gets to Case "Collar22-32" it gets stuck in the do until loop and as a result will keep on adding to PnlsToProduce(until it crashes cos the number is too big) instead of only running through the do until loop when it finds that component
Private Sub knittingdetailsheaderdataset()
bundlenum = 1
Dim SQL As String
Dim Adapter As New OleDbDataAdapter
Dim dt As New DataTable
Using con As New OleDbConnection(cnString)
Dim cmd As New OleDbCommand()
SQL = "Select bla bla
FROM bla bla
INNER Join bla bla"
(it's a very long sql statement, and not relevent to my issue)
cmd.Connection = con
cmd.CommandText = SQL
Adapter.SelectCommand = cmd
Adapter.Fill(dt)
For dr As Integer = 0 To dt.Rows.Count - 1
componentName = dt(dr)(6)
knittOrderID = dt(dr)(4)
componentID = dt(dr)(3)
sizeID = dt(dr)(5)
qtyppnl = dt(dr)(10)
Select Case componentName
Case "Sleeve", "Front", "Body", "Back"
MxBndleSz = 36
PnlsToProduce = dt(dr)(11)
BuildKnittingRecords(MxBndleSz, componentID, sizeID, PnlsToProduce, qtyppnl, knittOrderID, bundlenum)
Case "Collar22-32"
MxBndleSz = 200
PnlsToProduce = 0
Do Until componentName <> "Collar22-32" Or dr = dt.Rows.Count - 1
PnlsToProduce += dt(dr)(11)
Loop
Select Case PnlsToProduce
Case 50 To 100
PnlsToProduce = PnlsToProduce + 1
Case 101 To 250
PnlsToProduce = PnlsToProduce + 2
Case Is > 250
PnlsToProduce = PnlsToProduce + 3
End Select
BuildKnittingRecords(MxBndleSz, componentID, sizeID, PnlsToProduce, qtyppnl, knittOrderID, bundlenum)
End Select
Next
End Using
End Sub
Hence my question is, why is it doing this and how do I solve it?
This is my code for the BuildknittingRecord() sub, not sure if it's relevant in solving my issue:
Private Sub BuildKnittingRecords(ByRef MaxBundleSz As Integer, ByRef compID As Integer, ByRef sizeID As Integer, ByRef PnlsToproduce As Integer, ByRef QtyPerPanel As Integer, ByRef KnittingOrderID As Integer, ByRef bundlenum As Integer)
pnls2prod = PnlsToproduce
Dim cmdstring As String
Do Until pnls2prod < 10
If bundlenum < 10 Then
bundleNo = txtbatchno.Text & "-K0" & bundlenum
Else
bundleNo = txtbatchno.Text & "-K" & bundlenum
End If
bundlenum += 1
If pnls2prod <= MaxBundleSz Then
PanelsToMake = pnls2prod
cmdstring = " INSERT INTO [KN - KnittingDetailsHeader] (BatchNo, BundleNo, ComponentID, SizeID, PanelsToMake, QtyPerPanel, KnittingOrderID) VALUES('" & txtbatchno.Text & "', '" & bundleNo & "', " & compID & ", " & sizeID & ", " & PanelsToMake & ", " & QtyPerPanel & ", " & KnittingOrderID & ");"
Using con As New OleDbConnection(cnString)
Dim cmd As New OleDbCommand(cmdstring)
cmd.CommandType = CommandType.Text
cmd.Connection = con
cmd.Connection.Open()
cmd.ExecuteNonQuery()
End Using
Exit Do
Else
If pnls2prod < 10 Then
PanelsToMake = pnls2prod + MaxBundleSz
cmdstring = " INSERT INTO [KN - KnittingDetailsHeader] (BatchNo, BundleNo, ComponentID, SizeID, PanelsToMake, QtyPerPanel, KnittingOrderID) VALUES('" & txtbatchno.Text & "', '" & bundleNo & "', " & compID & ", " & sizeID & ", " & PanelsToMake & ", " & QtyPerPanel & ", " & KnittingOrderID & ");"
Using con As New OleDbConnection(cnString)
Dim cmd As New OleDbCommand(cmdstring)
cmd.CommandType = CommandType.Text
cmd.Connection = con
cmd.Connection.Open()
cmd.ExecuteNonQuery()
End Using
Exit Do
End If
PanelsToMake = MaxBundleSz
pnls2prod = pnls2prod - MaxBundleSz
cmdstring = " INSERT INTO [KN - KnittingDetailsHeader] (BatchNo, BundleNo, ComponentID, SizeID, PanelsToMake, QtyPerPanel, KnittingOrderID) VALUES('" & txtbatchno.Text & "', '" & bundleNo & "', " & compID & ", " & sizeID & ", " & PanelsToMake & ", " & QtyPerPanel & ", " & KnittingOrderID & ");"
Using con As New OleDbConnection(cnString)
Dim cmd As New OleDbCommand(cmdstring)
cmd.CommandType = CommandType.Text
cmd.Connection = con
cmd.Connection.Open()
cmd.ExecuteNonQuery()
End Using
End If
Loop
End Sub

oleDbexception was unhandled by user code

I cannot see the added data in the data table when debugging starts it doesn't have any error but when I click button1 it shows me errors (unhandled by user code) unclosed quotation mark after the character string ')'
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As OleDbConnection
Dim strInsert As String
Dim cmdInsert As OleDbCommand
Dim vt As Byte, vm As Byte
Dim sze As Byte
con = New OleDbConnection("Integrated Security=SSPI;Packet Size=4096;Data Source=.;Tag with column collation when possible=False;Initial Catalog=borjara;Use Procedure for Prepare=1;Auto Translate=True;Persist Security Info=False;Provider=SQLOLEDB.1;Workstation ID=ABDI;Use Encryption for Data=False")
If RadioButton4.Checked = True Then vt = 0
If RadioButton5.Checked = True Then vt = 1
If RadioButton6.Checked = True Then vm = 0
If RadioButton7.Checked = True Then vm = 1
If RadioButton8.Checked = True Then vm = 2
If RadioButton9.Checked = True Then szs = 1
If RadioButton10.Checked = True Then szs = 0
con.Open()
strInsert = "insert Into t1(jens) Values (" & DropDownList1.SelectedItem.Text & "')"
cmdInsert = New OleDbCommand(strInsert, con)
cmdInsert.ExecuteNonQuery()//error is here
con.Close()
con.Open()
strInsert = "insert Into t1(bazsho) Values (" & DropDownList2.SelectedItem.Text & "')"
cmdInsert = New OleDbCommand(strInsert, con)
cmdInsert.ExecuteNonQuery()
con.Close()
con.Open()
strInsert = "insert Into t1(name and lastname,email,number,address,lenght,wideth,turi,glasstype,glass) Values (" & n & ",'" & TextBox1.Text(+" / " + TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "'," & vt & "," & vm & "," & szs & "')")
cmdInsert = New OleDbCommand(strInsert, con)
cmdInsert.ExecuteNonQuery()
con.Close()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
End Sub
End Class
It looks like there is no opening quote in the values of the first two Inserts.

Can't UPDATE a large image size that was INSERTed in the database in asp.net

Here is the problem, when I insert an image (let's call it Data A) which is 1.32MB, it will be inserted successfully. But if I will insert again Data A(but it will update now because i used UPSERT, see my code), it will not be updated and it will result to connection time out.
But when i insert another data (Data B) which is only 4KB, it will also be inserted successfully and if I will insert again into it(which is update), it will be updated successfully. What can I do? I cannot understand the problem. I already made my command timeout for 2 mins but nothing happened and it just loaded forever. I also used sql transaction but it did nothing.
Here is my code:
Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim strConnString As String = DataSource.ConnectionString
Using con As New SqlConnection(strConnString)
Dim SQLStr As String
Dim base64String = TextArea1.Value
Dim imageBytes As Byte() = Convert.FromBase64String(base64String)
Dim FileSizeOfIMG As String
FileSizeOfIMG = imageBytes.Length
Dim ImageTypeDataOfImage As New SqlParameter("#Data", SqlDbType.Image)
ImageTypeDataOfImage.Value = imageBytes
SQLStr = "SELECT 1 FROM [Patient_Data].[dbo].[tbPatientImage] where HospNum='" & Session.Item("HospNum") & "'" & _
" and IDNum='" & Session.Item("IDNum") & "' and FileType= '" & lblHeader.Text & "'"
Dim cmd As New SqlCommand(SQLStr, con)
cmd.Connection = con
con.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
If reader.Read() Then
SQLStr = "UPDATE [Patient_Data].[dbo].[tbPatientImage] SET PatImage= #Data, FileSize= '" & FileSizeOfIMG.ToString & "' , TransDate = GetDate() where HospNum='" & Session.Item("HospNum") & "' and IDNum='" & Session.Item("IDNum") & "' and FileType= '" & lblHeader.Text & "'"
Else
SQLStr = "INSERT INTO [Patient_Data].[dbo].[tbPatientImage](HospNum,IDNum, DoctorID, PatImage , FileType, FileName, FileSize , TransDATE) " & _
" VALUES (#HospNum,#IDNum, #DoctorID, #Data, #FileType, 'Patient Photo' , #FileSize, GETDATE())"
End If
reader.Close()
cmd.CommandText = SQLStr
cmd.Parameters.AddWithValue("#HospNum", Session.Item("HospNum"))
cmd.Parameters.AddWithValue("#IDNum", Session.Item("IDNum"))
cmd.Parameters.AddWithValue("#DoctorID", Session.Item("DoctorID"))
cmd.Parameters.AddWithValue("#FileType", lblHeader.Text)
cmd.Parameters.AddWithValue("#FileSize", FileSizeOfIMG.ToString)
cmd.Parameters.Add(ImageTypeDataOfImage)
cmd.ExecuteNonQuery()
con.Close()
GetData()
End Using
End Sub
I haven't figured out what causes this but i have figured out a remedy by having a delete query first then insert data.
SQLStr = "delete FROM [Patient_Data].[dbo].[tbPatientImage] where HospNum='" & Session.Item("HospNum") & "'" & _
" and IDNum='" & Session.Item("IDNum") & "' and FileType= '" & lblHeader.Text & "'"
Dim cmd As New SqlCommand(SQLStr, con)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
SQLStr = " INSERT INTO [Patient_Data].[dbo].[tbPatientImage](HospNum,IDNum, DoctorID, PatImage , FileType, FileName, FileSize , TransDATE) " & _
" VALUES (#HospNum,#IDNum, #DoctorID, #Data, #FileType, 'Patient Photo' , #FileSize, GETDATE())"
cmd.CommandText = SQLStr
'cmd.CommandTimeout = 120
cmd.Parameters.AddWithValue("#HospNum", Session.Item("HospNum"))
cmd.Parameters.AddWithValue("#IDNum", Session.Item("IDNum"))
cmd.Parameters.AddWithValue("#DoctorID", Session.Item("DoctorID"))
cmd.Parameters.AddWithValue("#FileType", lblHeader.Text)
cmd.Parameters.AddWithValue("#FileSize", FileSizeOfIMG)
cmd.Parameters.Add(ImageTypeDataOfImage)
cmd.ExecuteNonQuery()
con.Close()
GetData()
lblMessage.Text = "Saved."
End Using
End Sub

I'm trying to insert info into two tables on a single btnclick. Its writing to only one table still. Can't see what I'm missing. [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If (Not Page.IsPostBack) Then
Dim strDatabaseNameAndLocation As String
strDatabaseNameAndLocation = Server.MapPath("databob.mdb")
Dim strSQLCommand As String
strSQLCommand = "SELECT Customers.* FROM Customers ORDER BY Customers.CustomerID DESC;"
Dim objOleDbConnection As System.Data.OleDb.OleDbConnection
objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation)
objOleDbConnection.Open()
Dim objOleDbCommand As System.Data.OleDb.OleDbCommand
objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection)
Dim objOleDbDataReader As System.Data.OleDb.OleDbDataReader
objOleDbDataReader = objOleDbCommand.ExecuteReader()
Dim datDataTable As System.Data.DataTable
datDataTable = New System.Data.DataTable()
datDataTable.Load(objOleDbDataReader)
objOleDbConnection.Close()
End If
If (Not Page.IsPostBack) Then
Dim strDatabaseNameAndLocation As String
strDatabaseNameAndLocation = Server.MapPath("databob.mdb")
Dim strSQLCommand2 As String
strSQLCommand2 = "SELECT CardType, CardNumber, Valid, Expiry, 3Digit FROM Orders ORDER BY Orders.OrderID DESC;"
Dim objOleDbConnection As System.Data.OleDb.OleDbConnection
objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation)
objOleDbConnection.Open()
Dim objOleDbCommand As System.Data.OleDb.OleDbCommand
objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand2, objOleDbConnection)
Dim objOleDbDataReader As System.Data.OleDb.OleDbDataReader
objOleDbDataReader = objOleDbCommand.ExecuteReader()
Dim datDataTable As System.Data.DataTable
datDataTable = New System.Data.DataTable()
datDataTable.Load(objOleDbDataReader)
objOleDbConnection.Close()
End If
End Sub
Protected Sub btnContinue_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strFirstName As String
Dim strLastName As String
Dim strAddress As String
Dim strPostcode As String
Dim strHomeNo As String
Dim strMobileNo As String
Dim strEmail As String
Dim strCardType As String
Dim strCardNumber As String
Dim strValid As String
Dim strExpiry As String
Dim str3Digit As String
strFirstName = tbxFirstName.Text
strLastName = tbxLastName.Text
strAddress = tbxAddress.Text
strPostcode = tbxPostcode.Text
strHomeNo = tbxHomeNo.Text
strMobileNo = tbxMobileNo.Text
strEmail = tbxEmail.Text
strCardType = ddlCardType.Text
strCardNumber = tbxCardNumber.Text
strValid = tbxValid.Text
strExpiry = tbxExpiry.Text
str3Digit = tbx3Digit.Text
Dim strDatabaseNameAndLocation As String
strDatabaseNameAndLocation = Server.MapPath("databob.mdb")
Dim strSQLCommand As String
strSQLCommand = "INSERT INTO Customers(FirstName, LastName, Address, Postcode, HomeNo, MobileNo, Email) " & _
"Values ('" & strFirstName & "', '" & strLastName & "', '" & strAddress & "', '" & strPostcode & "', '" & strHomeNo & "', '" & strMobileNo & "', '" & strEmail & "');"
Dim strSQLCommand2 As String
strSQLCommand2 = "INSERT INTO Orders(CardType, CardNumber, Valid, Expiry, 3Digit) " & _
"Values ('" & strCardType & "', '" & strCardNumber & "', '" & strValid & "', '" & strExpiry & "', '" & str3Digit & "');"
Dim objOleDbConnection As System.Data.OleDb.OleDbConnection
objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation)
objOleDbConnection.Open()
Dim objOleDbCommand As System.Data.OleDb.OleDbCommand
objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection)
objOleDbCommand.ExecuteNonQuery()
objOleDbConnection.Close()
strSQLCommand = "SELECT Customers.* FROM Customers ORDER BY Customers.CustomerID DESC;"
strSQLCommand2 = "SELECT Orders.* FROM Orders ORDER BY Orders.OrderID DESC;"
objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation)
objOleDbConnection.Open()
objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection)
Dim objOleDbDataReader As System.Data.OleDb.OleDbDataReader
objOleDbDataReader = objOleDbCommand.ExecuteReader()
Dim datDataTable As System.Data.DataTable
datDataTable = New System.Data.DataTable()
datDataTable.Load(objOleDbDataReader)
objOleDbConnection.Close()
tbxFirstName.Text = ""
tbxLastName.Text = ""
tbxAddress.Text = ""
tbxPostcode.Text = ""
tbxHomeNo.Text = ""
tbxMobileNo.Text = ""
tbxEmail.Text = ""
ddlCardType.Text = ""
tbxCardNumber.Text = ""
tbxValid.Text = ""
tbxExpiry.Text = ""
tbx3Digit.Text = ""
End Sub
objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection)
objOleDbCommand.ExecuteNonQuery()
That executes the first one but you do not do it again for strSQLCommand2
-- as an aside please look into parameterization of your queries. You are just asking for sql injection with that.
INSERT INTO Orders(Orders( looks a tad fishy to me (unless that's a C&P error posting this question)
And as Ken points out, if you're wanting to run both queries (rather than replace one with the other), you probably want:
strSQLCommand = strSQLCommand & " INSERT INTO Orders(CardType, CardNumber, Valid, Expiry, 3Digit) " & _
Your problem is that you are trying to use same string variable to hold both sqls, in fact you are overwriting the first one with the second one, modify your code like this
Dim strSQLCommand As String
Dim strSQLCommand2 As String
strSQLCommand = "INSERT INTO Customers(FirstName, LastName, Address, Postcode, HomeNo, MobileNo, Email) " & _
"Values ('" & strFirstName & "', '" & strLastName & "', '" & strAddress & "', '" & strPostcode & "', '" & strHomeNo & "', '" & strMobileNo & "', '" & strEmail & "');"
strSQLCommand2 = "INSERT INTO Orders(Orders(CardType, CardNumber, Valid, Expiry, 3Digit) " & _
"Values ('" & strCardType & "', '" & strCardNumber & "', '" & strValid & "', '" & strExpiry & "');"
and then afterwards you need to execute both statements, also you should add a transaction, something like this
objOleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & strDatabaseNameAndLocation)
objOleDbConnection.Open()
Dim objTrans As System.Data.OleDb.OleDbTransaction;
objTrans=objOleDbConnection.BeginTransaction();
try
{
Dim objOleDbCommand As System.Data.OleDb.OleDbCommand
objOleDbCommand = New System.Data.OleDb.OleDbCommand(strSQLCommand, objOleDbConnection)
objOleDbCommand.ExecuteNonQuery()
objOleDbCommand.CommandText =strSQLCommand2;
objOleDbCommand.ExecuteNonQuery()
objTrans.Commit();
}
catch{Exception ex}
{
objTrans.Rollback();
}
finally
{
objOleDbConnection.Close()
}
Just pulling it out of my head, can be a typo on it, but you can get the idea

Resources