SYNTEX ERROR in C#

Discussion in 'Software' started by ghufran, Jul 28, 2008.

  1. ghufran

    ghufran

    Joined:
    Jul 28, 2008
    Messages:
    1
    Hi, Can any one please tell what is wrong in this . I am getting syntax error on insert time . Please reply (sysali_ghufran@hotmail.com)
    CODE
    --
    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; // <- for database methods
    using System.Globalization; // Date
    using System.Data.SqlClient;


    namespace assign2
    {
    public partial class Addstudent : Form
    {
    public OleDbConnection database;
    DataGridViewButtonColumn editButton;
    DataGridViewButtonColumn deleteButton;

    public Addstudent()
    {
    InitializeComponent();
    string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb";

    database = new OleDbConnection(connectionString);
    database.Open();

    try
    {
    database = new OleDbConnection(connectionString);
    database.Open();

    string queryString1 = "SELECT StudentID, FirstName, LastName,Address,PhoneNumber FROM students";
    //loadDataGrid(queryString1);


    }
    catch (Exception ex)
    {
    return;
    }



    }

    private void studentsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
    {
    this.Validate();
    this.studentsBindingSource.EndEdit();
    this.studentsTableAdapter.Update(this.studentDataSet.Students);

    }

    private void Addstudent_Load(object sender, EventArgs e)
    {
    // TODO: This line of code loads data into the 'studentDataSet.Students' table. You can move, or remove it, as needed.
    this.studentsTableAdapter.Fill(this.studentDataSet.Students);

    }

    private void button1_Click(object sender, EventArgs e)
    {

    int name = Int32.Parse(studentIDTextBox.Text);
    string name1 = firstNameTextBox.Text;
    string name2 = lastNameTextBox.Text;
    string name3 = addressTextBox.Text;
    int name4 = Int32.Parse(phoneNumberTextBox.Text);

    string SQLString = "";

    SQLString = "INSERT INTO Students(StudentID, FirstName, LastName, address,phonenumber) VALUES('" + name + "','" + name1 + "','" + name2 + "','" + name3 + "'," + name4 + ");";

    OleDbCommand SQLCommand = new OleDbCommand();
    SQLCommand.CommandText = SQLString;
    SQLCommand.Connection = database;
    int response = -1;

    try
    {
    response = SQLCommand.ExecuteNonQuery();

    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    if (response >= 1) MessageBox.Show("Student is added to database", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);


    }
    }
    }
     
    ghufran, Jul 28, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWljaGFlbA==?=

    Error using DOS window, ever seen this error?

    =?Utf-8?B?TWljaGFlbA==?=, Apr 15, 2004, in forum: Microsoft Certification
    Replies:
    1
    Views:
    618
    Marlin Munrow
    Apr 15, 2004
  2. =?Utf-8?B?RGF2aWQgRGF5?=

    DNS error or Time Out error following Broadband Upgrade

    =?Utf-8?B?RGF2aWQgRGF5?=, May 4, 2005, in forum: Microsoft Certification
    Replies:
    2
    Views:
    812
    BrainLock
    May 6, 2005
  3. =?Utf-8?B?VGVtcGxlUmluZ2xldHM=?=

    Windows Media Player 10 error "An Internal Application error has o

    =?Utf-8?B?VGVtcGxlUmluZ2xldHM=?=, Jun 27, 2005, in forum: Microsoft Certification
    Replies:
    1
    Views:
    3,191
    Don Carter
    Jun 27, 2005
  4. Ismaiel
    Replies:
    0
    Views:
    6,155
    Ismaiel
    Oct 26, 2004
  5. kanman
    Replies:
    0
    Views:
    5,495
    kanman
    Apr 25, 2009
Loading...

Share This Page