Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. error while inserting table with autonumber using MsAccess

error while inserting table with autonumber using MsAccess

Scheduled Pinned Locked Moved C#
databasecsharpgraphicshelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sakthi06karthi
    wrote on last edited by
    #1

    hi to all ....... I am using c#.net windows application. for database MSAccess. while inserting values in the table it show that ((Number of query values and destination fields are not the same.)) data base field id name pass autonumber text text and my coding using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Data.OleDb; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Reservation : Form { OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\intel\\Desktop\\DB.mdb"); OleDbCommand cmd; public Reservation() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { cn.Open(); cmd = new OleDbCommand("insert into Table1 values('" + textBox1.Text + "','" + textBox2.Text + "')", cn); cmd.ExecuteNonQuery(); MessageBox.Show("inserted"); } } } while insert its not inserted......... by sakthi

    J M 2 Replies Last reply
    0
    • S sakthi06karthi

      hi to all ....... I am using c#.net windows application. for database MSAccess. while inserting values in the table it show that ((Number of query values and destination fields are not the same.)) data base field id name pass autonumber text text and my coding using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Data.OleDb; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Reservation : Form { OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\intel\\Desktop\\DB.mdb"); OleDbCommand cmd; public Reservation() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { cn.Open(); cmd = new OleDbCommand("insert into Table1 values('" + textBox1.Text + "','" + textBox2.Text + "')", cn); cmd.ExecuteNonQuery(); MessageBox.Show("inserted"); } } } while insert its not inserted......... by sakthi

      J Offline
      J Offline
      Jerry Wang
      wrote on last edited by
      #2

      What is the schema of the Table1 ? It seems that you can insert into the table, but missing the field value for some additional required field. insert into Table1 values('field1', 'field2', 'field3', ..., 'fieldn') n = Table1's field's count

      S 2 Replies Last reply
      0
      • J Jerry Wang

        What is the schema of the Table1 ? It seems that you can insert into the table, but missing the field value for some additional required field. insert into Table1 values('field1', 'field2', 'field3', ..., 'fieldn') n = Table1's field's count

        S Offline
        S Offline
        sakthi06karthi
        wrote on last edited by
        #3

        database fields r id username password 1 sakthi sakthi 2 ramesh ramesh 3 u u (autoincreament) and my coding using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Data.OleDb; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Reservation : Form { OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\intel\\Desktop\\DB.mdb"); OleDbCommand cmd; public Reservation() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { cn.Open(); cmd = new OleDbCommand("insert into Table1 values('" + textBox1.Text +"','" + textBox2.Text + "')", cn); cmd.ExecuteNonQuery(); MessageBox.Show("inserted"); } } } while insert its not inserted......... by sakthi

        1 Reply Last reply
        0
        • J Jerry Wang

          What is the schema of the Table1 ? It seems that you can insert into the table, but missing the field value for some additional required field. insert into Table1 values('field1', 'field2', 'field3', ..., 'fieldn') n = Table1's field's count

          S Offline
          S Offline
          sakthi06karthi
          wrote on last edited by
          #4

          HERE I USE ID AS AUTOINCREMENT

          X 1 Reply Last reply
          0
          • S sakthi06karthi

            HERE I USE ID AS AUTOINCREMENT

            X Offline
            X Offline
            Xmen Real
            wrote on last edited by
            #5

            no caps until you have something special to say else it consider as you're shouting and nobody will reply you. Plus use Edit button at botton-right corner of the message to edit it. ;)

            TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia>

            ----------------------------------------------- 128 bit encrypted signature, crack if you can

            1 Reply Last reply
            0
            • S sakthi06karthi

              hi to all ....... I am using c#.net windows application. for database MSAccess. while inserting values in the table it show that ((Number of query values and destination fields are not the same.)) data base field id name pass autonumber text text and my coding using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Data.OleDb; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Reservation : Form { OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\intel\\Desktop\\DB.mdb"); OleDbCommand cmd; public Reservation() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { cn.Open(); cmd = new OleDbCommand("insert into Table1 values('" + textBox1.Text + "','" + textBox2.Text + "')", cn); cmd.ExecuteNonQuery(); MessageBox.Show("inserted"); } } } while insert its not inserted......... by sakthi

              M Offline
              M Offline
              musefan
              wrote on last edited by
              #6

              try using square brackets around your column names. i.e. [Column1], [Column2] etc. Also, do not include your AutoNumber column when inserting, this will be assigned automatically - you cannot write to it manually third thing - make sure you use command parameters with your code...

              cmd = new OleDbCommand("INSERT INTO Table1 ([column1], [column2]) VALUES (@1, @2)", cn);
              cmd.Parameters.Add("@1", OleDbType.Char).Value = textBox1.Text;
              cmd.Parameters.Add("@2", OleDbType.Char).Value = textBox2.Text;

              NOTE how the column names have been specified to avoid trying to insert into the AutoNumber column

              Life goes very fast. Tomorrow, today is already yesterday.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups