473,695 Members | 2,782 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 3829
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
3289
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
2125
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
10645
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
12178
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
1905
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
3003
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
8675
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
13096
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
1563
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
8630
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8568
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
9115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8825
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7660
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...
0
4340
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
4579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2272
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1976
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.