7 Replies - 444 Views - Last Post: 18 October 2018 - 08:05 AM Rate Topic: -----

#1 rizsoomro   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 26-January 18

insert into statement (0x80040E14) in C# in access database

Posted 17 October 2018 - 11:13 AM

I try to make a data entry form but this error comes when i click on save button.

private void btnSave_Click(object sender, EventArgs e)
    {
        try
        {

            string InsertPur = "Insert into [Booking](FormCode,NameApplicant,FatherName,[Occupation],MonthlyIncome,CNICNo,ApplicantAge,[Address],MobileNo,ResidenceTel,NoOfDependents,Nominee,PlotBanglowNo,Catog,[Type],Block,Size,TotalCost,RoadFacing,Corner,WestOpen,ParkFacing,OtherCharges,TotalRs,ProjectName,[UserName],[UserType],CreatedDate,ModifiedDate) values (" + txtFormID.Text + ",'" + txtNApp.Text + "','" + txtFName.Text + "','" + txtOccupation.Text + "'," + txtMIncome.Text + "," + txtCNIC.Text + "," + txtAAge.Text + ",'" + txtAddress.Text + "'," + txtMobile.Text + "," + txtRTel.Text + "," + txtNoOfDependents.Text + ",'" + txtNominee.Text + "'," + txtPlotNo.Text + "," + Catog + ",'" + txtType.Text + "','" + txtBlock.Text + "','" + cboxSize.Text + "'," + txtTCost.Text + "," + txtRFacing.Text + "," + txtCorner.Text + "," + txtWOpen.Text + "," + txtPFacing.Text + "," + txtOCharges.Text + "," + txtTotalRs.Text + ",'" + lblProject.Text + "','" + lblLoginID.Text + "','" + lblUserType.Text + "','" + datepicker.Value.Date.ToLongDateString() + "','" + datepicker.Value.Date.ToLongDateString() + "')";
            OleDbDataAdapter da = new OleDbDataAdapter(InsertPur, con);
            DataSet ds = new DataSet();
            da.Fill(ds);

            MetroMessageBox.Show(this, "Application Form Saved successfully", "MAARS Software");

            ClearData();
            NewFormCode();
            txtFormID.Focus();
        }
        catch (Exception ex)
        {
            MetroFramework.MetroMessageBox.Show(this, "Error" + ex, "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
        }
c# visual-studio-2017 ms



Is This A Good Question/Topic? 0
  • +

Replies To: insert into statement (0x80040E14) in C# in access database

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14502
  • View blog
  • Posts: 58,141
  • Joined: 12-June 08

Re: insert into statement (0x80040E14) in C# in access database

Posted 17 October 2018 - 11:24 AM

Please copy/paste the entire error message here.

You should also switch to using parameters. Most likely that's an issue.

https://docs.microso...framework-4.7.2
Was This Post Helpful? 2
  • +
  • -

#3 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1550
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: insert into statement (0x80040E14) in C# in access database

Posted 17 October 2018 - 11:30 AM

The INSERT INTO statement contains one or more unknown field name(s).

Check your database has all these columns in place?

Or perhaps 'Catog' should be 'Catalog' .... who knows.. could be a few things...

This post has been edited by snoopy11: 17 October 2018 - 11:39 AM

Was This Post Helpful? 0
  • +
  • -

#4 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7295
  • View blog
  • Posts: 15,182
  • Joined: 16-October 07

Re: insert into statement (0x80040E14) in C# in access database

Posted 18 October 2018 - 04:26 AM

Dude! In txtFormID.Text I'm totally writing: "null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null); truncate table [Booking]". Just saying...

Looks like you have a mixture of char and numeric there. Follow the link on parameters above.

Obligatory xkcd: Posted Image
Was This Post Helpful? 1
  • +
  • -

#5 rizsoomro   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 26-January 18

Re: insert into statement (0x80040E14) in C# in access database

Posted 18 October 2018 - 05:07 AM

View Postmodi123_1, on 17 October 2018 - 11:24 AM, said:

Please copy/paste the entire error message here.

You should also switch to using parameters. Most likely that's an issue.

https://docs.microso...framework-4.7.2


this is entire error message;


ErrorSystem.Data.OleDb.OleDbException (0x80040E14): Syntax error in INSERT INTO statement,
at System.Data.OleDb.OleDbExceptionCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbExceptionCommandTextForSingleResult(tagDBPARAMS dbParams, Object executeResult)

View Postsnoopy11, on 17 October 2018 - 11:30 AM, said:

The INSERT INTO statement contains one or more unknown field name(s).

Check your database has all these columns in place?

Or perhaps 'Catog' should be 'Catalog' .... who knows.. could be a few things...


i checked again n again but nothing missing or missplaced. and dude 'Catog' is 'Catogery' i tried to avoid SQL reserved words so i wrote it catog :whistling:

View Postbaavgai, on 18 October 2018 - 04:26 AM, said:

Dude! In txtFormID.Text I'm totally writing: "null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null); truncate table [Booking]". Just saying...

Looks like you have a mixture of char and numeric there. Follow the link on parameters above.

Obligatory xkcd: Posted Image



Dude! txtFormID.Text work autogenerated number he get from NewFormCode(); function
Was This Post Helpful? 0
  • +
  • -

#6 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1550
  • View blog
  • Posts: 4,930
  • Joined: 20-March 10

Re: insert into statement (0x80040E14) in C# in access database

Posted 18 October 2018 - 06:18 AM

Dude !!


Catogery is spelled 'Category'.... Dude !!

And Dude, the error tells you explicitly that one or more field names in the Insert Into statement either doesn't exist in the database or you have missed out one or more field names that exist in the database but do not exist in the insert into statement.

The way you have just crammed everything into one line is it really a surprise this has occurred....? Dude !!
Was This Post Helpful? 1
  • +
  • -

#7 andrewsw   User is offline

  • head thrashing
  • member icon

Reputation: 6630
  • View blog
  • Posts: 27,099
  • Joined: 12-December 12

Re: insert into statement (0x80040E14) in C# in access database

Posted 18 October 2018 - 07:40 AM

I suspect an issue could be with the long date formatting.
(Again, using parameters would avoid issues with date formatting.)

To debug the huge string that you have built, save it into a variable, print it out and try and execute it directly.
Was This Post Helpful? 1
  • +
  • -

#8 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7295
  • View blog
  • Posts: 15,182
  • Joined: 16-October 07

Re: insert into statement (0x80040E14) in C# in access database

Posted 18 October 2018 - 08:05 AM

View Postrizsoomro, on 18 October 2018 - 07:07 AM, said:

Dude! txtFormID.Text work autogenerated number he get from NewFormCode(); function


And all the other fields? There is no user entry there at all? Wait, why would you even have an auto generated field in a Text control?

The answer is still to bind your parameters. That will automatically sanitize your inputs. More primitive languages will sometimes sanitize the strings themselves. Still, in no scenario is raw pass through of user entered data acceptable.

Rather than doing work in the button click, consider another method, or even another object, that takes the properly typed values as parameters.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1