Access database error "Cannot open action query"

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 2
Reputation: sarabonn is an unknown quantity at this point 
Solved Threads: 0
sarabonn sarabonn is offline Offline
Newbie Poster

Access database error "Cannot open action query"

 
0
  #1
Nov 19th, 2008
Hallo everyone,

Iam using C# to insert a row into access table. Iam getting the values to insert from textbox. I got the error "cannot open action query". Here is my code
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. txt1 = textBox1.Text;
  4. txt2 = textBox2.Text;
  5. String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Userinfo.accdb";
  6.  
  7. OleDbConnection connection = new OleDbConnection(connectionString);
  8. OleDbDataAdapter adapter = new OleDbDataAdapter();
  9.  
  10.  
  11. OleDbCommand command = new OleDbCommand();
  12. // Create the InsertCommand.
  13.  
  14. command.CommandType = CommandType.Text;
  15. command.CommandText = "INSERT INTO userinfo (Username, Pwd) VALUES (‘" + txt1 + "’ , ‘" + txt2 + "’)";
  16. command.Connection = connection;
  17. //command.Parameters.Add("txt1", OleDbType.Char, 5, "Username");
  18. //command.Parameters.Add("txt2", OleDbType.VarChar, 10, "Pwd");
  19.  
  20. adapter.InsertCommand = command;
  21.  
  22. connection.Open();
  23.  
  24. command.ExecuteNonQuery();
  25. connection.Close();
  26. }
.

Any idea ?.

Thank you.

Dinesh.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: reena12 is an unknown quantity at this point 
Solved Threads: 4
reena12 reena12 is offline Offline
Light Poster

Re: Access database error "Cannot open action query"

 
0
  #2
Nov 20th, 2008
Hi,

private void button1_Click(object sender, EventArgs e)
{
txt1 = textBox1.Text;
txt2 = textBox2.Text;
String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Userinfo.accdb";

OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand command = new OleDbCommand("INSERT INTO userinfo (Username, Pwd) VALUES (‘" + txt1 + "’ , ‘" + txt2 + "’)";
command.ExecuteNonQuery();
connection.Close();
}
Reena Mehta

Remember to click on Mark as answer on the post that helped

http://www.indianic.com
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 65
Reputation: Renukavani is an unknown quantity at this point 
Solved Threads: 6
Renukavani Renukavani is offline Offline
Junior Poster in Training

Re: Access database error "Cannot open action query"

 
0
  #3
Nov 21st, 2008
hi
u need to specify proper database extension. i think here s the probelm ? u given
String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Userinfo.accdb";
so plz change to mdb this s ths access dbase extension and u have to use
connection.open()
chk it this and let me know

if ur problem solved plz mark as Solved
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: sarabonn is an unknown quantity at this point 
Solved Threads: 0
sarabonn sarabonn is offline Offline
Newbie Poster

Re: Access database error "Cannot open action query"

 
0
  #4
Nov 21st, 2008
thank you for your reply. actually i solved the problem but the problem is not because of the extension. This is office 2007 access database extension. ".mdb" is the extension of the previous version office. Anyway Thank you for reply.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC