locked
INSERT INTO an access DB File RRS feed

  • Question

  • User507348793 posted

    How does the insert into statement look for access

    this is what i came up with

    private void Insertdataintoaccess(String ItemCode,String BookingNumber,String ClientDescription)
            {
                OleDbConnection oleconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtAccDBDataPath.Text + ";Jet OLEDB:Database Password="+txtAccPass.Text +"");
                OleDbCommand olecomm = new OleDbCommand("INSERT INTO Bookings ('ItemCode','BookingNumber','ClientDescription') VALUES('" + Convert.ToString(ItemCode) + @"','"
                   + Convert.ToString(BookingNumber.ToString())+ @"','"
                   + Convert.ToString(ClientDescription.ToString())+@"')'",oleconn);
                oleconn.Open();
                olecomm.ExecuteNonQuery();


    this works for SQLSERVER but not sure how to modify code for Access mdb database file

    with this i get the following error

    Missing semicolomn (;) at the end of SQL Statement

    Monday, August 16, 2010 7:07 AM

Answers

  • User1283497924 posted

    Hi,

    just make small change in ur query

    INSERT INTO Bookings ([ItemCode],[BookingNumber],[ClientDescription]) VALUES('" + Convert.ToString(ItemCode) + "',' "
                   + Convert.ToString(BookingNumber.ToString())+ "','"
                   + Convert.ToString(ClientDescription.ToString())+"')

    OleDbCommand olecomm = new OleDbCommand("INSERT INTO Bookings ('ItemCode','BookingNumber','ClientDescription') VALUES('" + Convert.ToString(ItemCode) + @"','"
                   + Convert.ToString(BookingNumber.ToString())+ @"','"
                   + Convert.ToString(ClientDescription.ToString())+@"')
    '",oleconn);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 16, 2010 7:43 AM

All replies

  • User1283497924 posted

    Hi,

    just make small change in ur query

    INSERT INTO Bookings ([ItemCode],[BookingNumber],[ClientDescription]) VALUES('" + Convert.ToString(ItemCode) + "',' "
                   + Convert.ToString(BookingNumber.ToString())+ "','"
                   + Convert.ToString(ClientDescription.ToString())+"')

    OleDbCommand olecomm = new OleDbCommand("INSERT INTO Bookings ('ItemCode','BookingNumber','ClientDescription') VALUES('" + Convert.ToString(ItemCode) + @"','"
                   + Convert.ToString(BookingNumber.ToString())+ @"','"
                   + Convert.ToString(ClientDescription.ToString())+@"')
    '",oleconn);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 16, 2010 7:43 AM
  • User507348793 posted

    @Vinay 

    It worked thanks

    Monday, August 16, 2010 8:37 AM
  • User-1199946673 posted

    It worked thanks
     

    Just because it works doesn't mean that's good practice! Maybe you should take a look at the links I provided in my earlier post, especially the second link?

    Monday, August 16, 2010 9:25 AM
  • User507348793 posted

    Im real busy now maybe look into it later


    Monday, August 16, 2010 9:59 AM