473,396 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Error with an insert query

Hi
When i'm try to insert data it gives an error saying that Error in INSERT INTO statement.
This is my code

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.OleDb;
  8. using System.Data;
  9.  
  10. namespace WebApplication2
  11. {
  12.     public partial class WebForm2 : System.Web.UI.Page
  13.     {
  14.         public string vdate;
  15.         public int vaccno;
  16.         public int vamount;
  17.         public int i;
  18.         public decimal vcbalance;
  19.         public decimal balance;
  20.  
  21.  
  22.  
  23.         protected void Page_Load(object sender, EventArgs e)
  24.         {
  25.  
  26.         }
  27.  
  28.         protected void Button2_Click(object sender, EventArgs e)
  29.         {
  30.             //Session.Abandon();
  31.  
  32.             Session.Abandon();
  33.             Response.Redirect("Default.aspx");
  34.  
  35.  
  36.  
  37.         }
  38.  
  39.  
  40.  
  41.         protected void Button1_Click(object sender, EventArgs e)
  42.         {
  43.             vdate = TextBox3.Text;
  44.             vaccno = int.Parse(TextBox1.Text);
  45.             vamount = int.Parse(TextBox2.Text);
  46.  
  47.  
  48.             OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=C:/Samashika/aaa/Database1.mdb");
  49.             try
  50.             {
  51.                 con.Open();
  52.             }
  53.             catch (OleDbException) { }
  54.  
  55.  
  56.             //string qry = "INSERT INTO Transaction VALUES (@vdate,@accno,amount)";
  57.             OleDbCommand com = new OleDbCommand("INSERT INTO Transaction VALUES (@vdate,@accno,amount)", con);
  58.            // OleDbCommand com = new OleDbCommand(qry, con);
  59.             com.Parameters.AddWithValue("@vdate", vdate);
  60.             com.Parameters.AddWithValue("@accno", vaccno);
  61.             com.Parameters.AddWithValue("@amount", vamount);
  62.  
  63.             i = com.ExecuteNonQuery();
  64.             if (i > 0)
  65.             {
  66.                 Label5.Text = "record addedd";
  67.             }
  68.  
  69.  
  70.  
  71.         }
  72.  
  73.  
  74.  
  75.  
  76.     }
  77. }
May 24 '11 #1
2 1722
Stewart Ross
2,545 Expert Mod 2GB
You are inserting three values, two of which are parameterised. The third variable, amount, is not the name of the parameter @amount you have set up, nor does it match the name of the variable vamount which you use to set the parameter.

-Stewart
May 24 '11 #2
Hi
I set the variables as you said.But it didn't work.
Thanks
May 27 '11 #3

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

Similar topics

2
by: avinash | last post by:
hello myself avinash i am developing on application having vb 6 as front end and sql server 7 as back end. when i use insert query to insert data in table then the date value of that query is...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
5
by: Annie | last post by:
hello guys, I have little experience working with C# and MS Access ... I am having an insert query with one datetime field and a boolean and couple of text and number fields as below: ...
0
by: clickon | last post by:
I want to use an INSERT Query as the value for the UpdateCommand property of an SQL datasource, anyone know if this will actually work ? The reason i want to do it is bacause i am taking values...
3
by: tyngtyng | last post by:
hi... i'm new to the php and now i'm getting an error to insert my data inside the form..and also undefined index in latest_updated...... Now,i'm having trouble catching what i'm doing...
2
by: csharpa | last post by:
Hi, I wrote an insert query in TableAdapter and it gave me this error “Failed to get schema for this query”. The query that I wrote was this INSERT INTO STUDENT (S_ID,...
1
by: kiny3k | last post by:
hi, i have written this insert query for inserting data in database : "insert into leavemaster (leave_code,leave_desc,leave_type, leave_days, leave_valid_month, leave_amount, effective_date,...
8
by: Santy | last post by:
Hello All, I am new to DB2, Currently i am using DB2 version 8.02 personal edition on Windows XP Professional. And Facing problem with rowlock in insert query. I have created a sample database...
1
by: Luqman | last post by:
I have created a Insert Query in Sql Data Source using Oracle Database, with the parameters, and its connected with DetailView Control. When I try to Insert through DetailView Control, Illegal...
2
by: kaushalgajjar | last post by:
Hi there i have a problem in inserting a query to Access database. i am having a column which is AutoNumber and if i skip that field in insert query from vb.net then it is giving me an error "Syntax...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.