2

This is how my table looks like

    /****** Object:  Table [dbo].[tdn_Winners]    Script Date: 08/12/2016 18:55:35 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[tdn_Winners](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [MemberId] [int] NULL,
    [PrizeNodeId] [int] NULL,
    [CampaignNodeId] [int] NULL,
    [TransactionId] [int] NULL,
 CONSTRAINT [PK_TND_Winners] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

And I am inserting some values to this table like this

        string insertquery = "INSERT INTO [dbo].[tdn_Winners] ([MemberId] ,
    [PrizeNodeId] ,[CampaignNodeId] ,[TransactionId])  VALUES(@MemberId, 
    @PrizeNodeId, @CampaignNodeId, @TransactionId";


                int rowsAffected = sqlHelper.ExecuteNonQuery(insertquery, 
sqlHelper.CreateParameter(parameterName: "@MemberId", value: 1), 
sqlHelper.CreateParameter(parameterName: "@PrizeNodeId", value: 1),
sqlHelper.CreateParameter(parameterName: 
"@CampaignNodeId",value: 1), sqlHelper.CreateParameter(parameterName: 
"@TransactionId", value: 1));

Everything looks ok to me, But this throws an error like this

System.Data.SqlClient.SqlException: Incorrect syntax near '@TransactionId'.

Can anyone please point out what I am doing wrong here?

2
  • 2
    You forgot closing ")" in your command. Commented Dec 8, 2016 at 13:30
  • 1
    Your insert command is missing a closing parenthesis at the end ). Commented Dec 8, 2016 at 13:30

3 Answers 3

5

You are missing closing bracket:

 string insertquery = "INSERT INTO [dbo].[tdn_Winners] ([MemberId] ,
[PrizeNodeId] ,[CampaignNodeId] ,[TransactionId])  VALUES(@MemberId, 
@PrizeNodeId, @CampaignNodeId, @TransactionId)";
Sign up to request clarification or add additional context in comments.

Comments

2

I think you are forgot to close the bracket.

VALUES(@MemberId, @PrizeNodeId, @CampaignNodeId, @TransactionId)";

Comments

0

The closing bracket after @TransactionId was missing.

Add it and retry. It should work.

   "INSERT INTO [dbo].[tdn_Winners] (
    [MemberId] ,
    [PrizeNodeId] ,
    [CampaignNodeId] ,
    [TransactionId]) 
     VALUES(
       @MemberId, 
       @PrizeNodeId, 
       @CampaignNodeId,
       @TransactionId)";

Comments

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.