473,387 Members | 1,603 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,387 software developers and data experts.

SQL insert error

Dear All

I am trying to execute following cod

Sub SubmitBtn_Click(ByVal Sender As Object, ByVal E As EventArgs
Dim DBConn As OleDbConnectio
Dim DBInsert As New OleDbComman
DBConn = New OleDbConnection("PROVIDER="
& "Microsoft.Jet.OLEDB.4.0;"
& "DATA SOURCE="
& Server.MapPath("Emps.mdb;")
DBInsert.CommandText = "Insert Into Employees "
& "(LastName, FirstName, PhoneNumber, EmailAddress, "
& "Notes, DepartmentID) values ("
& "'" & Replace(txtLastName.Text, "'", "''") & "', "
& "'" & Replace(txtFirstName.Text, "'", "''") & "', "
& "'" & Replace(txtPhoneNumber.Text, "'", "''") & "', "
& "'" & Replace(txtEmailAddress.Text, "'", "''")
& "', "
& "'" & Replace(txtNotes.Text, "'", "''") & "', "
& ddlDepartments.SelectedItem.Value & ")
DBInsert.Connection = DBCon
DBInsert.Connection.Open(
DBInsert.ExecuteNonQuery(
Response.Redirect("./index.aspx"
End Su

while executing following
DBInsert.ExecuteNonQuery(

query i
Insert Into Employees (LastName, FirstName, PhoneNumber, EmailAddress, Notes, DepartmentID) values ('asdfas', 'asdf', 'asdfasfdasdf', 'asf', 'asdfasdf', 3

I get an error saying as follows, Whats happening... it's new to me.. more to that its an example striaght copy paste from one book
Operation must use an updateable query.
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: Operation must use an updateable query

Source Error:

Line 58: DBInsert.Connection = DBCon
Line 59: DBInsert.Connection.Open(
Line 60: DBInsert.ExecuteNonQuery(
Line 61: Response.Redirect("./index.aspx"
Line 62: End Su
Source File: c:\inetpub\wwwroot\WebApplication1\add1.aspx.vb Line: 60

Stack Trace:

[OleDbException (0x80004005): Operation must use an updateable query.
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method
System.Data.OleDb.OleDbCommand.ExecuteNonQuery(
WebApplication1.add1.SubmitBtn_Click(Object Sender, EventArgs E) in c:\inetpub\wwwroot\WebApplication1\add1.aspx.vb:6
System.Web.UI.WebControls.Button.OnClick(EventArgs e
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData
System.Web.UI.Page.ProcessRequestMain(

Nov 18 '05 #1
3 1581
Hi Pravin

I've recreated the table in SQL Server 2000 using varchar(50) for all fields
but DepartmentID for which I used int.
I had no problem running the Query in SQL Analyzer. However, you might want
to check your table keys. I had a similar odd problem before and it turned
out to be caused by an misdefined primary key.

Martin
"Pravin A. Sable" <my***********@ccs.neu.edu> wrote in message
news:5B**********************************@microsof t.com...
Dear All,

I am trying to execute following code

Sub SubmitBtn_Click(ByVal Sender As Object, ByVal E As EventArgs)
Dim DBConn As OleDbConnection
Dim DBInsert As New OleDbCommand
DBConn = New OleDbConnection("PROVIDER=" _
& "Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("Emps.mdb;"))
DBInsert.CommandText = "Insert Into Employees " _
& "(LastName, FirstName, PhoneNumber, EmailAddress, " _
& "Notes, DepartmentID) values (" _
& "'" & Replace(txtLastName.Text, "'", "''") & "', " _
& "'" & Replace(txtFirstName.Text, "'", "''") & "', " _
& "'" & Replace(txtPhoneNumber.Text, "'", "''") & "', " _
& "'" & Replace(txtEmailAddress.Text, "'", "''") _
& "', " _
& "'" & Replace(txtNotes.Text, "'", "''") & "', " _
& ddlDepartments.SelectedItem.Value & ")"
DBInsert.Connection = DBConn
DBInsert.Connection.Open()
DBInsert.ExecuteNonQuery()
Response.Redirect("./index.aspx")
End Sub

while executing following
DBInsert.ExecuteNonQuery()

query is
Insert Into Employees (LastName, FirstName, PhoneNumber, EmailAddress, Notes, DepartmentID) values ('asdfas', 'asdf', 'asdfasfdasdf', 'asf',
'asdfasdf', 3)

I get an error saying as follows, Whats happening... it's new to me.. more to that its an example striaght copy paste from one book.
Operation must use an updateable query.
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: Operation must use an updateable query.
Source Error:
Line 58: DBInsert.Connection = DBConn
Line 59: DBInsert.Connection.Open()
Line 60: DBInsert.ExecuteNonQuery()
Line 61: Response.Redirect("./index.aspx")
Line 62: End Sub
Source File: c:\inetpub\wwwroot\WebApplication1\add1.aspx.vb Line: 60

Stack Trace:
[OleDbException (0x80004005): Operation must use an updateable query.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr) System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult) System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult) System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method) System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
WebApplication1.add1.SubmitBtn_Click(Object Sender, EventArgs E) in c:\inetpub\wwwroot\WebApplication1\add1.aspx.vb:60 System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
stBackEvent(String eventArgument) System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()

Nov 18 '05 #2
WJ
Trap the Exception.Message (try{}catch{Exception: e}) or turn on Debug/Trace
to find the exact line that is broken. Normally, a table must also be
existed and opened successfully before any maintenance operations
(add/chg/del) can be performed. The exception message would give you
specific error.

John
Nov 18 '05 #3
Hi Martin,

Sorry for not specifying problem completely, I am getting careless after
coming to academics again.

The database is simple access xp database. I did some search on google
and found that, this error is due to privileges of machinename/ASP.net
user. I gave ASP.net user administrative privileges but yet no change.
In IIS I gave read, write, permission for this database file, but no
change. I am kind of stuck. Definitely this error has to do something
with Access and file permission but I am not sure how to solve them.

Best Regards,
Pravin

Martin Feuersteiner wrote:
Hi Pravin

I've recreated the table in SQL Server 2000 using varchar(50) for all fields
but DepartmentID for which I used int.
I had no problem running the Query in SQL Analyzer. However, you might want
to check your table keys. I had a similar odd problem before and it turned
out to be caused by an misdefined primary key.

Martin
"Pravin A. Sable" <my***********@ccs.neu.edu> wrote in message
news:5B**********************************@microsof t.com...
Dear All,

I am trying to execute following code

Sub SubmitBtn_Click(ByVal Sender As Object, ByVal E As EventArgs)
Dim DBConn As OleDbConnection
Dim DBInsert As New OleDbCommand
DBConn = New OleDbConnection("PROVIDER=" _
& "Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("Emps.mdb;"))
DBInsert.CommandText = "Insert Into Employees " _
& "(LastName, FirstName, PhoneNumber, EmailAddress, " _
& "Notes, DepartmentID) values (" _
& "'" & Replace(txtLastName.Text, "'", "''") & "', " _
& "'" & Replace(txtFirstName.Text, "'", "''") & "', " _
& "'" & Replace(txtPhoneNumber.Text, "'", "''") & "', " _
& "'" & Replace(txtEmailAddress.Text, "'", "''") _
& "', " _
& "'" & Replace(txtNotes.Text, "'", "''") & "', " _
& ddlDepartments.SelectedItem.Value & ")"
DBInsert.Connection = DBConn
DBInsert.Connection.Open()
DBInsert.ExecuteNonQuery()
Response.Redirect("./index.aspx")
End Sub

while executing following
DBInsert.ExecuteNonQuery()

query is
Insert Into Employees (LastName, FirstName, PhoneNumber, EmailAddress,


Notes, DepartmentID) values ('asdfas', 'asdf', 'asdfasfdasdf', 'asf',
'asdfasdf', 3)

I get an error saying as follows, Whats happening... it's new to me.. more


to that its an example striaght copy paste from one book.


Operation must use an updateable query.
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: Operation must use an


updateable query.
Source Error:
Line 58: DBInsert.Connection = DBConn
Line 59: DBInsert.Connection.Open()
Line 60: DBInsert.ExecuteNonQuery()
Line 61: Response.Redirect("./index.aspx")
Line 62: End Sub
Source File: c:\inetpub\wwwroot\WebApplication1\add1.aspx.vb Line: 60

Stack Trace:
[OleDbException (0x80004005): Operation must use an updateable query.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32


hr)

System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object&


executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior,


Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior


behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
WebApplication1.add1.SubmitBtn_Click(Object Sender, EventArgs E) in


c:\inetpub\wwwroot\WebApplication1\add1.aspx.vb:60
System.Web.UI.WebControls.Button.OnClick(EventArgs e)


System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
stBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler


sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()


Nov 18 '05 #4

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

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
7
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
6
by: harborboy76 | last post by:
Hi, I am trying to insert a large number of rows into a table inside a SPL. But every time, I run the SPL, the table is locked because of the INSERT. When I tried to issue a COMMIT, right after...
8
by: 73blazer | last post by:
Hello, I'm looking for a way to make some of my insert templates more readable by placing comments in between the values. I cannot seem to find a way to do this with DB2, is there a way? I'm...
3
by: MP | last post by:
Hi Posted this several hours ago to another ng but it never showed up thought i'd try here. using vb6, ado, .mdb, jet4.0, no access given table tblJob with field JobNumber text(10) 'The...
3
by: mahajanvit | last post by:
Hi one and all I got this problem during my project. So in order to solve this I made a very small application. I am trying to insert using SP and sqldatasource control. I know that while using...
9
by: anachronic_individual | last post by:
Hi all, Is there a standard library function to insert an array of characters at a particular point in a text stream without overwriting the existing content, such that the following data in...
2
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.