2 Replies - 229 Views - Last Post: 03 February 2012 - 06:13 AM Rate Topic: -----

Topic Sponsor:

#1 demiching  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-February 12

Unknown field name error in c#

Posted 02 February 2012 - 08:48 PM

Hi,

I'm currently trying to solve a error which I encountered in my C# program.
I want to insert into my Access database the name I type into my nameTextBox after I click the 'ADD' button.

This is the code in my addButton_Click.

 
private void addNameButton_Click(object sender, EventArgs e)
        {
            OleDbConnection myCon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=K:\\stopwatchApp\\time.mdb");
            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = myCon;
            //cmd.CommandType = CommandType.Text;
            cmd.CommandText = "INSERT into Table1 (TeamName) Values('"+inputNameTextBox.Text+"')";
            //cmd.Connection = myCon;
            myCon.Open();
            cmd.ExecuteNonQuery();
            myCon.Close();

            MessageBox.Show("Record updated!");
}



This is the error I encountered:
The INSERT INTO statement contains the following unknown field name: 'TeamName'. Make sure you have typed the name correctly, and try the operation again.

Attached is my GUI.

Regards,
Demi C.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Unknown field name error in c#

#2 AdamSpeight2008  Icon User is offline

  • Coder-ian
  • member icon

Reputation: 1401
  • View blog
  • Posts: 7,358
  • Joined: 29-May 08

Re: Unknown field name error in c#

Posted 02 February 2012 - 09:05 PM

That error reference some issue related to field names used in the database.
Is it spelled correctly? Correct casing?

Also use query parameters instead, to lessen SQL injection.

Do think a image of your GUI is really helpful?
Issue: Which control is referred to by what names??
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is online

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1451
  • View blog
  • Posts: 5,763
  • Joined: 21-March 08

Re: Unknown field name error in c#

Posted 03 February 2012 - 06:13 AM

This error is pretty obvious. There is no column in Table1 called TeamName.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1