error while inserting table with autonumber using MsAccess
-
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
-
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
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
-
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
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
-
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
HERE I USE ID AS AUTOINCREMENT
-
HERE I USE ID AS AUTOINCREMENT
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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
-
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
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.