Inserting data into ms access database 2007 from visual stud

May 8 2015 12:58 AM
hi
i am new to .net and i am try to Inserting data into ms access database 2007 from visual studio 2005 using c#.net.
i got an error OleDbException was unhanded. Syntax error in INSERT INTO statement.
my code is here

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using Microsoft.VisualBasic;

namespace WindowsApplication2
{
    public partial class Form4 : Form
    {
        private OleDbConnection cn1;
        private OleDbCommand cmd;
        private string sql;
        private OleDbDataReader reader;
        int cnt = 0;


        public Form4()
        {
            cn1 = new OleDbConnection();
            cn1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Users\\hp\\Links\\Documents\\proposed system database\\new ATM Embed Database.mdb";
            cn1.Open();
            InitializeComponent();

        }
private void savebtn_Click(object sender, EventArgs e)
        {
            
            Int32 Account_No, PIN_No;
            Account_No = Int32.Parse(AccounttextBox.Text);
            PIN_No = Int32.Parse(PINtextBox.Text);

            sql = "Insert into ATM(C_Name,Account_No,Card_No,PIN_No)values('" + NametextBox.Text + "','" + AccounttextBox.Text + "','" + CardtextBox.Text + "','" + PINtextBox.Text + "',)";
            cmd = new OleDbCommand(sql, cn1);
            
                int n =cmd.ExecuteNonQuery();
                

               if (n > 0)
                {
                    MessageBox.Show("Record Has Been Saved !!");
                    AccounttextBox.Text = "" + (Account_No + 1);
                    NametextBox.Text = "";
                    CardtextBox.Text = "";
                    PINtextBox.Text = "";

                }
                else
                {
                    MessageBox.Show("Record Not Saved !!");

                }
                cn1.Close();
            }

        }
}
Please help me. 
suggest me solution of this problem.

Answers (3)