[COLOR=#0000ff]Hi everyone,[/COLOR]
[COLOR=#0000ff]I’m new here and also new in ASP.NET . I have a question about insert function that I use to insert the data from the web to the access database. I’m using the Microsoft Visual.Net and create a form in asp in C#. I create 1 field name with a textbox id “TextboxName” and a submit button, when I click the Submit button and it should call the insert(); function and get the value in the Texbox Name, save it to the Access Database. The code runs fine up until [/COLOR][COLOR=#000000]myCommand.ExecuteNonQuery(); [COLOR=blue]and print out an error, Can someone give me the right direction of why/where do I miss something in the code. Thanks in advance.[/COLOR][/COLOR]
[FONT=Arial]**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. [/FONT]
[FONT=Arial]**Exception Details: **System.Data.OleDb.OleDbException: Operation must use an updateable query.[/FONT]
[FONT=Arial]Source Error: [/FONT]
Line 223: //myCommand.Connection = myConnection;Line
224: //myConnection.Open();[COLOR=red]Line 225: myCommand.ExecuteNonQuery();[/COLOR]
Line 226: myCommand.Connection.Close();
Line 227:
[COLOR=#0000ff]private[/COLOR] [COLOR=#0000ff]void[/COLOR] insert ()
{
[COLOR=#008000]//Local Declarations[/COLOR]
[COLOR=#0000ff]string[/COLOR] myConnectionString;[COLOR=#0000ff]string[/COLOR] myInsertQuery;
OleDbCommand myCommand;
OleDbConnection myConnection;
SqlCommand cmd;
[COLOR=#008000]//Variable initialaztion[/COLOR]
myConnectionString = “”;
myInsertQuery = “”;
myCommand = [COLOR=#0000ff]null[/COLOR];
myConnection = [COLOR=#0000ff]null[/COLOR];
cmd = [COLOR=#0000ff]null[/COLOR];
[COLOR=#008000]//if the connection string is null, use a default.[/COLOR]
[COLOR=#0000ff]if[/COLOR] (myConnectionString == “”)
{
myConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Password=;User ID=;Data Source= c:/inetpub/wwwroot/bankdb.mdb”;
}
myConnection = [COLOR=#0000ff]new[/COLOR] OleDbConnection (myConnectionString);
[COLOR=#008000]// Build a SQL Insert statement string for all the input-form field values. [/COLOR]
myInsertQuery = “insert into bank (Name) Values (@TextBoxName)”;
[COLOR=#008000]// Initialize the OleDbCommand with the new myInsertQuery string and the connection information.[/COLOR]
myCommand = [COLOR=#0000ff]new[/COLOR] OleDbCommand(myInsertQuery, myConnection);
[COLOR=#008000]// Create new parameters for the OleDBCommand object and initialize them to the input-form field values.[/COLOR]
[COLOR=#008000]//myCommand.Parameters.Add("@TextBoxLenderName", OleDbType.VarChar, 50, “LenderName”);[/COLOR]
myCommand.Parameters.Add([COLOR=#0000ff]new[/COLOR] OleDbParameter("@TextBoxName", OleDbType.VarChar, 50));
myCommand.Parameters["@TextBoxName"].Value = Name.Text;
myCommand = [COLOR=#0000ff]new[/COLOR] OleDbCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
}