Problem to update or insert any Data from C# to Access Database

I have created a very simple database in Access and by using DataAdapter in C#.
I can Load(View) Data in my C# front End and also can Delete Data But
when I tried to Inser or Edit there is a error, "Syntex Error into INSERT INTO ".
But I think the Syntex is ok ... I have checked the SQL command and it is bug free.

dataAdapter.InsertCommand = conn.CreateCommand();
dataAdapter.InsertCommand.CommandText =
"INSERT INTO student (StudentID,name,roll,year) VALUES(@StudentID,@name,@roll,@year)";
AddParams(dataAdapter.InsertCommand,"StudentID","name","roll","year");


I have make this program with the help of C# leasring School Leasen 13.

Comments

  • : I have created a very simple database in Access and by using DataAdapter in C#.
    : I can Load(View) Data in my C# front End and also can Delete Data But
    : when I tried to Inser or Edit there is a error, "Syntex Error into INSERT INTO ".
    : But I think the Syntex is ok ... I have checked the SQL command and it is bug free.
    :
    : dataAdapter.InsertCommand = conn.CreateCommand();
    : dataAdapter.InsertCommand.CommandText =
    : "INSERT INTO student (StudentID,name,roll,year) VALUES(@StudentID,@name,@roll,@year)";
    : AddParams(dataAdapter.InsertCommand,"StudentID","name","roll","year");
    :
    :
    : I have make this program with the help of C# leasring School Leasen 13.
    :
    :

    Hi,

    I'm most certain that name are a keyword to Access, you can
    resolve this by placing square brackets around the column names
    in the insert statement like this
    "INSERT INTO Student([StudentID], [name], [roll], [year])
    VALUES( ?, ?, ?, ?)"

    Hope this helps you.

    // Patrik
  • : : I have created a very simple database in Access and by using DataAdapter in C#.
    : : I can Load(View) Data in my C# front End and also can Delete Data But
    : : when I tried to Inser or Edit there is a error, "Syntex Error into INSERT INTO ".
    : : But I think the Syntex is ok ... I have checked the SQL command and it is bug free.
    : :
    : : dataAdapter.InsertCommand = conn.CreateCommand();
    : : dataAdapter.InsertCommand.CommandText =
    : : "INSERT INTO student (StudentID,name,roll,year) VALUES(@StudentID,@name,@roll,@year)";
    : : AddParams(dataAdapter.InsertCommand,"StudentID","name","roll","year");
    : :
    : :
    : : I have make this program with the help of C# leasring School Leasen 13.
    : :
    : :
    :
    : Hi,
    :
    : I'm most certain that name are a keyword to Access, you can
    : resolve this by placing square brackets around the column names
    : in the insert statement like this
    : "INSERT INTO Student([StudentID], [name], [roll], [year])
    : VALUES( ?, ?, ?, ?)"
    :
    : Hope this helps you.
    :
    : // Patrik
    :

    Hi,

    I've connected to a Access DB with the OleDbDataAdapter and the Adapter generated some code. Aa result i see at the top of my programm the following code when i completed also the creation of a dataSet:

    System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;

    namespace WindowsUZB
    {
    ///
    /// Summary description for Arbeidsbelemmering.
    ///
    public class Arbeidsbelemmering : System.Windows.Forms.Form
    {
    private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
    private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
    private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
    private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
    private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
    private System.Data.OleDb.OleDbConnection oleDbConnection1;
    private WindowsUZB.arbeidsbelemmeringDS arbeidsbelemmeringDS1;

    When i look at the grey part in the code that will expand when i click on it,i see all the specific update and delete commands and the connection string to the database.
    So when i call the oleDbDataAdapter.Update method and fill in the name of the dataSet the actual update takes place when i push the Opslaan (Update).
    In this code "arbeidsbelemmeringenDS1"is the name of the dataSet and "arbeidsbelemmeringen" the name of the table in the database.


    private void Opslaan_Click(object sender, System.EventArgs e)
    {
    try
    {
    this.BindingContext[arbeidsbelemmeringDS1,"arbeidsbelemmering"].EndCurrentEdit();
    this.oleDbDataAdapter1.Update(arbeidsbelemmeringDS1);
    }
    catch (System.Exception eEndEdit)
    {
    System.Windows.Forms.MessageBox.Show(eEndEdit.Message);
    }

    }

    For me this code works and the data is saved in the database.

    With friendluy greatings,


    Yepper65

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories