Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
my exception is **"Number of query values and destination fields are not the same."**
i am using Windows7,VS2010-c#.net4.0 and MS-Access2010 database.
Please let me know how to resolve this error. My code is as follows

C#
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\baswaraj\\Documents\\Database1.accdb");
 string query = "insert into information values('" + textBox1.Text + "'," + textBox2.Text + "," + textBox3.Text + ")";
            OleDbCommand cmd = new OleDbCommand(query, con);
            cmd.CommandType = CommandType.Text;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
}


Edit: Code formatted
Posted
Updated 19-Apr-12 1:03am
v2

No. of item you are trying to insert via query string and number of column in the Information table is not same. And this the reason.

So try to insert same no of column values into Information table via query string.

Hope it helps.
 
Share this answer
 
Comments
VJ Reddy 19-Apr-12 19:58pm    
To the point. 5!
Mohammad A Rahman 19-Apr-12 20:01pm    
Thank you very much VJ :)
Modify the query as follow
C#
string query="insert into information([First field name],[Second field name],[Third field name]) values('"+textbox1.Text+"',"+textbox2.Text+","+textbox3.Text+")";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900