943,851 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2018
  • C# RSS
Nov 19th, 2008
0

Access database error "Cannot open action query"

Expand Post »
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
C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sarabonn is offline Offline
2 posts
since Nov 2008
Nov 20th, 2008
0

Re: Access database error "Cannot open action query"

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();
}
Reputation Points: 12
Solved Threads: 4
Light Poster
reena12 is offline Offline
32 posts
since Oct 2008
Nov 21st, 2008
0

Re: Access database error "Cannot open action query"

hi
u need to specify proper database extension. i think here s the probelm ? u given
Quote ...
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
Quote ...
connection.open()
chk it this and let me know

if ur problem solved plz mark as Solved
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008
Nov 21st, 2008
0

Re: Access database error "Cannot open action query"

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sarabonn is offline Offline
2 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Dragging and dropping objects out of the windows forms.
Next Thread in C# Forum Timeline: Connecting to database through programming





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC