2

I am trying to insert a new row into my database using an INSERT INTO SQL query. I am not sure what I am doing wrong as I am not the more experienced programmer.

I am trying to add the integer value 1 to the column Question Type when the button is pressed. My primary key increments automatically so that shouldn't be a problem as all of the other columns can be NULL.

INSERT INTO dbo.Questions (Question Type)
VALUES (1)

When I press OK to this query an error displays saying :

An error occurred while trying to create the parameterized query:

Error in list of function arguments: 'Type' not recognized. Incomplete parameters or column list. Unable to parse query text.

This is the code for the table I am trying to add to:

CREATE TABLE [dbo].[Questions] (
[QuestionID]     INT           IDENTITY (1, 1) NOT NULL,
[Actual answer]  NVARCHAR (50) NULL,
[Question Space] NVARCHAR (50) NULL,
[Question Type]  INT           NULL,
PRIMARY KEY CLUSTERED ([QuestionID] ASC)
);
2
  • How about writing it as: INSERT INTO dbo.Questions VALUES (Null,Null,1) Commented Apr 17, 2015 at 11:13
  • I don't use search criteria builder but a glance online suggests that error is caused when your calling code uses a table adapter that expects a SELECT query. As @X.L.Ant requested, can we see the code that is submitting this SQL transaction request? Commented Apr 17, 2015 at 14:52

3 Answers 3

5

Try this.. If the column name has White Space, then the entire column name should be enclosed using Square Brackets ([]).

INSERT INTO dbo.Questions ([Question Type])
VALUES (1)

This is for SQL server... if it is MySQL then use ("") or (``)

Sign up to request clarification or add additional context in comments.

5 Comments

Not only whitespaces, but also any unauthorized character.
When I try this it says "Failed to get schema for this query."
I'm not 100% sure what you mean by DBMS, but I am creating a local network. I am using Microsoft Visual Studio Express 2013 and am using sql?
Are you using SQL Server
Yes I am using an SQL server
3

you not allowed to use spaces between column names. either use identifier with double quotes or square braces."" OR []

INSERT INTO dbo.Questions ("Question Type")
VALUES (1)

7 Comments

When I try this it says "Failed to get schema for this query."
@mot375 which database you using ? and put your table struture here
@mot375 along with the code you're using to execute that query.
'm not 100% sure what you mean by DBMS, but I am creating a local network. I am using Microsoft Visual Studio Express 2013 and am using sql? I don't really have any code that is related to that I am using the data grid view thingy that helps add a query for you
you are executing this query from c# or from database query panel
|
2

Since there is no code (yet) with access to that table, remove the whitespace in your column names.

1 Comment

I agree. It sounds like you are early in your project. It's a good time to change your column names so they have no spaces in them (or other non-alpha-numeric characters like dashes or underscores). Naming them like that will give you so much grief later on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.