Update Using a parametrized Query

J

jagdishl

Hi:
I have used the following code for my update query button I have used
VB.Net

Private Sub btncollections_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btncollections.Click
Const connstr As String = "Provider=sqloledb;Data Source=Athena;Initial
Catalog=OCACollections_DB;Integrated Security=SSPI;"
Dim objConn As New OleDbConnection(connstr)
Dim MYsql As String = "Insert into
tblCollectionReports(CasesAssessed,CostAssessed) Values
(@Cases,@AssessedCosts)"
Dim objcmd As New OleDbCommand(MYsql, objConn)
objcmd.CommandType = CommandType.StoredProcedure
With objcmd.Parameters
.Add(New OleDbParameter("@Cases", txtcases.Text))
.Add(New OleDbParameter("@AssessedCosts",
txtassessedcosts.Text))
End With
objcmd.Connection.Open()
objcmd.ExecuteNonQuery()
objcmd.Connection.Close()

Upon clicking I get the following error

Syntax error or access violation
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error or
access violation

Source Error:


Line 121: End With
Line 122: objcmd.Connection.Open()
Line 123: objcmd.ExecuteNonQuery()
Line 124: objcmd.Connection.Close()
Line 125: End Sub


Source File: C:\OCACollections\ProgramCollections.aspx.vb Line: 123

What is wrong with the above code please help?
 
S

S. Justin Gengo

jagdishl,

The first thing to check is if the account your website is running under has
been given permission to the SQL database. If your site is running as an
anonymous user then it should be using the IUSR_[Your Machine Name Here]
account, if you are running with <identity impersonate=true> in your
web.config then you are most likely running under the ASPNET account. Make
certain the appropriate account has been given access to run the update
procedure for starters.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top