Trouble UPDATING Access database with ASP.NET?

  • Thread starter Thread starter joe v
  • Start date Start date
J

joe v

Guest
I can SELECT np but I want to UPDATE and it's not working. I don't know if I am using bad code or if Access has some default setting that doesn't let you use UPDATE queries. I did disable the Action Query check box under options in Access so that I can run the query IN Access.

Here is my UPDATE code:

public void UpdateCount(string database, int newCount)
{
//Declare and Instantiate a new Database connection and Command variable, as well as a string to hold the command
System.Data.OleDb.OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + database + "");
conn.Open();
System.Data.OleDb.OleDbCommand command = new OleDbCommand();
command = conn.CreateCommand();
string strSQL;

strSQL = "UPDATE tblCounter SET tblCounter.[Counter] = newCount WHERE(((tblCounter.ID) = 1))";

command.CommandType = CommandType.Text;
command.CommandText = strSQL;
command.ExecuteNonQuery();
conn.Close();
}

---------------------

Remember, the SQL works in Access.

How can I get this to work?
 
any particular error ?.

or u can use

command=new oledbcommand(strsql,conn)
command.ExecuteNonQuery()

In place of this

command.CommandType = CommandType.Text;
command.CommandText = strSQL;
command.ExecuteNonQuery();

why are u using semicolons. Is this code you use in design or in Source code. ?
 
Back
Top