By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,899 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,899 IT Pros & Developers. It's quick & easy.

How to fix "Syntax error in INSERT INTO statement" using OLEDB?

P: 2
hi I am working on an application that manages the data in a access database. but i cant seem to get past this error.

When i try to run it it says:
"Syntax error in INSERT INTO statement" syntax error, I have made all the fields in database TEXT(255) so it cant be that.

any help regarding this will be much appreciated, i am new to datasets and would love any help or guides i can get on the matter.

Expand|Select|Wrap|Line Numbers
  1.                                                         string connstring = "Provider=Microsoft.Jet.OleDb.4.0;" +
  2.                                                                         @"Data Source=" + DBpath + ";" + "Jet OLEDB:Database Password=password;";
  3.                                                         OleDbConnection conn = new OleDbConnection(connstring);
  4.                                                         conn.Open();
  5.  
  6.                                                         OleDbDataAdapter dba = new OleDbDataAdapter("Select * FROM Teachers", conn);
  7.                                                         OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(dba);
  8.                                                         DataSet ds = new DataSet();
  9.                                                         dba.Fill(ds, "Teachers");
  10.                                                         DataTable dt = ds.Tables["Teachers"];
  11.                                                         DataRow studentRow = dt.NewRow();
  12.                                                         studentRow["TeachNo"] = "2";
  13.                                                         studentRow["TName"] = textBox1.Text;
  14.                                                         studentRow["TSurname"] = textBox2.Text;
  15.                                                         studentRow["Gender"] = comboBox1.Text;
  16.                                                         studentRow["Age"] = textBox3.Text;
  17.                                                         studentRow["Cell-No"] = textBox6.Text;
  18.                                                         studentRow["Tell-No"] = textBox5.Text;
  19.                                                         studentRow["Suburb"] = textBox9.Text;
  20.                                                         studentRow["Street-address"] = textBox11.Text;
  21.                                                         studentRow["E-Mail"] = textBox13.Text;
  22.                                                         dt.Rows.Add(studentRow);
  23.  
  24.  
  25.                                                         dba.Update(ds, "Teachers");
  26.                                                         conn.Close();
  27.                                                         //Save to Teacher
  28.  
My using statements:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.OleDb;
  10.  
any help would be much appreciated
Jan 22 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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