Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie problem inserting into table

Status
Not open for further replies.

cyexpert

Programmer
Jun 16, 2002
40
CY
im new to c# and i m trying to insert into a table so i made this custom code:
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%
string insertString = "INSERT INTO Users (Name) VALUES ('n')";
// Define the connection string we will use. This one is specific for Microsoft
// Access
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("magazine.mdb");
bool connectionOpen = false;
OleDbConnection connection = null;
try
{
// Define a new connection to the database and open the connection
connection = new OleDbConnection(connectionString);
connection.Open();
connectionOpen = true;
}
catch (Exception ex1)
{
// Connection failed. Put out an appropriate error message
%> <h2>Unable to Connect to the Database</h2>
<p> could not be added to the publishers table since I was unable to
connect to the books database.</p>
<% }
if (connectionOpen)
{
try
{
// Create a new command for this connection.
OleDbCommand cmd = new OleDbCommand(insertString, connection);

// Execute the insert
cmd.ExecuteNonQuery();
%>
<h2>Insert Successful</h2>
<p> has been added to the publishers table in the books database.</p>
<% }
catch (Exception ex2)
{
%>
<h2>Insert Failed</h2>
<p> could not be added to the publishers table in the books database.</p>
<p>The error that occured was: <%= ex2.Message %></p>
<% }
finally
{
// Close the connection
connection.Close();
}
}
%>

</body>
</html>

and i get the following error
Insert Failed
could not be added to the publishers table in the books database.

The error that occured was: Operation must use an updateable query.

what i m doing wrong. also if a have a field in my DB that is ID autoincrement i have to do something special?

Thanx for ur help
 
The ASPNET account is going to need write permissions on the folder that your database resides.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top