|
-
January 30th, 2005, 03:20 AM
#1
** Problem Updating MS Access DB **
Hi
I'm trying to update a MS Access Database from my ASP.NET Application. I keep getting this error:
Exception Details: System.Data.OleDb.OleDbException: Operation must use an updateable query.
I think it's because the .mdb file doesn't have write access. I'm using a Windows XP Pro machine, I want to know how set proper write access for the .mdb file for the ASPNET account.
Here is the code for reference:
Code:
DataSet ds;
OleDbDataAdapter adpt;
OleDbConnection conn = null;
private void Page_Load(object sender, System.EventArgs e)
{
conn = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0; " +
"User ID=Admin;" +
"Data Source=" + @"C:\Pets\Pets.mdb");
adpt =
new OleDbDataAdapter("Select * FROM PetType", conn);
ds = new DataSet();
adpt.Fill (ds , "table");
datagrid.DataSource = ds;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
OleDbCommand cmdInsert = conn.CreateCommand();
cmdInsert.CommandType = CommandType.Text;
cmdInsert.CommandText = "insert into PetType values (@Id," +
" @PetName, @PetType)";
cmdInsert.Parameters.Add("@Id", OleDbType.VarChar, 11);
cmdInsert.Parameters["@Id"].Value = 3;
cmdInsert.Parameters.Add("@PetName",OleDbType.VarChar, 20);
cmdInsert.Parameters["@PetName"].Value = "asas";
cmdInsert.Parameters.Add("@PetType",OleDbType.VarChar, 20);
cmdInsert.Parameters["@PetType"].Value = "bat";
cmdInsert.Parameters["@Id"].SourceVersion = DataRowVersion.Original;
adpt.InsertCommand = cmdInsert;
DataRow dr = ds.Tables[0].NewRow();
dr[0] = 3;
dr[1]="asas";
dr[2] ="dwsfsa";
ds.Tables[0].Rows.Add(dr);
datagrid.DataBind();
adpt.Update(ds, "table");
}
Please Help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|