473,769 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error "cannot open the action query"

69 New Member
hallo

Iam trying to insert a row into a access database using visual c# and iam getting an error " cannot open the action query". here is my code

Expand|Select|Wrap|Line Numbers
  1.  
  2. private void button1_Click(object sender, EventArgs e)
  3.         {
  4.      txt1 = textBox1.Text;
  5.             txt2 = textBox2.Text;
  6.             String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Userinfo.accdb";
  7.             OleDbConnection connection = new OleDbConnection(connectionString);
  8.                        OleDbCommand command = new OleDbCommand();           
  9.  
  10.  
  11.               command.CommandType = CommandType.TableDirect;
  12.               command.CommandText = "INSERT INTO userinfo (Username, Pwd) VALUES (‘" + txt1 + "’ , ‘" + txt2 + "’)";
  13.               command.Connection = connection;
  14.               connection.Open();
  15.               command.ExecuteNonQuery(); // getting in this line .
  16.               connection.Close();
  17.  
  18.  
any idea why is this error ?

Thank you.
Dinesh.
Nov 18 '08 #1
14 3840
Curtis Rutland
3,256 Recognized Expert Specialist
Please enclose your posted code in [CODE] [/CODE] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [CODE] [/CODE] tags in future.

MODERATOR
Nov 18 '08 #2
Plater
7,872 Recognized Expert Expert
Your CommandType should be
CommandType.Tex t

With TableDirect, I believe you would just make CommandText ="MyTableNam e" and it would return the contents of the entire table
Nov 18 '08 #3
sarabonn
69 New Member
Your CommandType should be
CommandType.Tex t

With TableDirect, I believe you would just make CommandText ="MyTableNam e" and it would return the contents of the entire table

hallo plater,

If i use the CommanType.Text it gives me error "No value given for one or more required parameters." in the line Command.Execute NonQuery();.

Thank you.

Dinesh.
Nov 19 '08 #4
MrMancunian
569 Recognized Expert Contributor
Instead of

Expand|Select|Wrap|Line Numbers
  1. command.CommandText = "INSERT INTO userinfo (Username, Pwd) VALUES (‘" + txt1 + "’ , ‘" + txt2 + "’)";
  2.  
use

Expand|Select|Wrap|Line Numbers
  1. command.InsertCommand = "INSERT INTO userinfo (Username, Pwd) VALUES (‘" + txt1 + "’ , ‘" + txt2 + "’)"; 
  2.  
Steven
Nov 19 '08 #5
sarabonn
69 New Member
Instead of

Expand|Select|Wrap|Line Numbers
  1. command.CommandText = "INSERT INTO userinfo (Username, Pwd) VALUES (‘" + txt1 + "’ , ‘" + txt2 + "’)";
  2.  
use

Expand|Select|Wrap|Line Numbers
  1. command.InsertCommand = "INSERT INTO userinfo (Username, Pwd) VALUES (‘" + txt1 + "’ , ‘" + txt2 + "’)"; 
  2.  
Steven
hallo steven,

Command is an object oldbcommand and it doesn't have the command.insertc ommand or do you mean oledbdataadapte r.InsertCommand ?..

thank you,

dinesh.
Nov 19 '08 #6
MrMancunian
569 Recognized Expert Contributor
hallo steven,

Command is an object oldbcommand and it doesn't have the command.insertc ommand or do you mean oledbdataadapte r.InsertCommand ?..

thank you,

dinesh.
Yes, sorry, I meant the DataAdapter.Ins ertCommand

Steven
Nov 19 '08 #7
sarabonn
69 New Member
Yes, sorry, I meant the DataAdapter.Ins ertCommand

Steven
hallo steven,

I changed the code like this with the dataadapter.ins ertcommand but iam getting a error "No value given for one or more required parameters." in the executenonquery () line. Iam sure about the table details.

Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.          txt1 = textBox1.Text;
  4.             txt2 = textBox2.Text;
  5.             txt3 = textBox1.Text;
  6.              txt4 = textBox2.Text;
  7.             OleDbConnection cnJetDB = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Userinfo.accdb");
  8.             cnJetDB.Open();
  9.             OleDbDataAdapter oleDa = new OleDbDataAdapter();
  10.             OleDbCommand cmdInsert = new OleDbCommand("INSERT INTO userinfo (Username, Pwd,Openid,ServerUrl)" + "VALUES (" + txt1 + "," + txt2 + "," + txt3 + "," + txt4 + ")", cnJetDB);
  11.  
  12.             oleDa.InsertCommand = cmdInsert;
  13.  
  14.             cmdInsert.ExecuteNonQuery();
  15.             cnJetDB.Close();
  16.  
any idea steven ?..

Thank you.
Dinesh
Nov 19 '08 #8
Plater
7,872 Recognized Expert Expert
I would say your problem is using the illegal quote character in your string. try using the regular ' single quote and see if that works for you.
Nov 19 '08 #9
r035198x
13,262 MVP
I would say your problem is using the illegal quote character in your string. try using the regular ' single quote and see if that works for you.
I don't see any quotes around the text values there at all legal or otherwise. My colleagues say that I'm getting old so my eyes may be the problem.
Nov 19 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3292
by: Koen | last post by:
Hi all, At work I created a database which is really helpful. The database is used by approx 15 users. Everything worked great, until I added some 'scoreboard' forms and reports. I get the "Cannot open any more databases" error. The 'scoreboard' form show a matrix of 6 columns, 7 rows. Each cell is calculated separate by (what I call complex) queries.
0
2132
by: Mr.KisS | last post by:
Hello. I'm under Windows XP PRO SP1, IIS 5.1 ans SQL SERVER 2005 Express. When i try to open a connexion with : <connectionStrings> <add name="AppCnxStr" connectionString="Server=KLEO\SQLEXPRESS;Integrated Security=True;Database=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\wizou.mdf" providerName="System.Data.SqlClient" />
2
10650
by: Mr.KisS | last post by:
Hello. I'm under Windows XP PRO SP1, IIS 5.1 ans SQL SERVER 2005 Express. When i try to open a connexion with : <connectionStrings> <add name="AppCnxStr" connectionString="Server=KLEO\SQLEXPRESS;Integrated Security=True;Database=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\wizou.mdf" providerName="System.Data.SqlClient" />
7
12185
by: Mathew Butler | last post by:
I'm investigating an issue I have when pulling data back from MS access I'm retrieving all rows from a column in a table of 5000 rows - accessing a column of type "memo" ( can be 65353 character long) . I'm pulling the data back using ODBC. Details are: Microsoft Access Driver 4.00.6306.00 Jet 4.0 release level that is currently installed (Msjet40.dll ) "Microsoft Jet Engine Library" 4.0.9025.0 After 291 rows are retreived I am...
3
1908
by: Joanne | last post by:
I have searched through previous threads regarding this error. I went back through all my code to make sure I closed and set to nothing all open db's and rs's. However, I still have one computer getting this error. This problem does not occur with any other users - some of whom use the database continuously. The user logs in, then goes to the Add Invoice form - it's a fairly simple form, single table recordset with a subform based on...
1
3009
by: bhushan11 | last post by:
hello sir i am searching in your site but i dont get how to place question about visual c++. so i am post this vc++ question in .net , sorre about that i am working on visual c++ lang. but i nave some problem. Linking... LINK : fatal error LNK1104: cannot open file "ProfUIS223md.lib" Error executing link.exe.
1
8683
by: alex21 | last post by:
Ok i am trying to use a Linq query to access a dictionary. public static Dictionary<string, Client> Clients = new Dictionary<string, Client>();Using this Linq query: IEnumerable<Staff> loginquery = from staff in Database.Staff where staff.Value.Passcode == txt_password.Text select staff;but i get the error Error 2 Cannot implicitly convert type...
3
13102
scubak1w1
by: scubak1w1 | last post by:
Hello, Did a search here, manuals and Googled, etc generally, so apologies if I did not find the answer to my issue - that is, I try and 'self help' as mush as I can... I adjusted my postgresql.conf file to set as on 'explain_pretty_print' Now in pgAdmin (1.10.0) when I right-click a database in the 'usual' way, Maintenance, any of the tasks, its starts OK, but I get a dialogue box up every (seeming) operation that the Maintenance is...
0
1565
by: Carruthers Pen | last post by:
The command to open outlook is below: conPATH_TO_OUTLOOK is C:\Program Files\Microsoft Office\Office14\outlook.exe retVal = Shell(conPATH_TO_OUTLOOK, vbMaximizedFocus) the error message is "cannot open your default e-mail folders. the infomation store could not be opened" If I go to the path target and click on outlook.exe then it opens without any problems it would seem that my user info is not being transmitted I am using windows7...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.