0

I create a table employee having 4 columns (eid, ename, ejob, esalary) after this when i m inserting values into this table i m getting error that

 invalid column name insert into employee values(1001,"Sachin","Army",50000) at column ename and ejob 

can any one tell me what does it mean Invalid column name and how can i remove this error.

2
  • Most probably you did not set the database name, and its using 'master' database by default Commented Jan 13, 2015 at 10:35
  • i did this but ........ Commented Jan 13, 2015 at 13:02

1 Answer 1

1

You are using double quote (") instead of single quote (').

Your query should be something like this:

insert into employee values(1001,'Sachin','Army',50000) 

It would be even better if you explicitly listed the columns of the table. The structure and order of the columns in the table can change, so if you don't list columns explicitly you can easily introduce hard to find bugs. Actually, even better would be if you explicitly included the table schema (usually dbo).

insert into dbo.employee(eid, ename, ejob, esalary) values(1001,'Sachin','Army',50000); 
Sign up to request clarification or add additional context in comments.

5 Comments

DialogResult d = MessageBox.Show("Are you sure of excuting the below Sql Statement?\n\n" + SqlStr, "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (d == DialogResult.Yes) { cmd.CommandText = SqlStr; int count = cmd.ExecuteNonQuery(); if (count > 0) MessageBox.Show("statement excuted succesfully"); else MessageBox.Show("statement execution failed");
i used this in my coding for inserting values into database.........at the point executequery();it dosent return any value while i m executing the insert query.
Your idea of single quotes is working in my SSMS but it is not working in widows form app.
I don't really know what is wrong with your C# code. I personally don't use this approach. Your problem consists of two parts. 1) Make sure in SSMS that the query itself is correct. It seems that this part is solved now. Good. 2) Check and fix C# code that executes the query. If you can't do it yourself, ask another question and explain what you are trying to achieve in C#, show your C# code, show the exact query that it tries to execute, show what errors/exceptions you are getting, etc. Thus your chances of getting a good answer would be high.
@SachinYadav, I'm glad you managed to work it out. Please tick my answer as approved if it helped you to solve the problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.