1

I've looked all over the internet to try and answer this but haven't had any luck. I imagine this is simple mistake on my end but cannot for the life of me determine what it is.

var queryString1 = "SELECT * FROM Product_Table WHERE CustomerInvoice='@custInvSel';";
        SqlCommand comm1 = new SqlCommand(queryString1, conn);
        comm1.Parameters.AddWithValue("@custInvSel", customerInvoiceSelected);

Basically the above code does not return any data whatsoever, despite the data being present. When the code reads

var queryString1 = "SELECT * FROM Product_Table WHERE CustomerInvoice='"+customerInvoiceSelected+"';";
        SqlCommand comm1 = new SqlCommand(queryString1, conn);

Everything works fine. No errors are thrown in either case which has stumped me. It just seems with parameters the query mixes up everything.

The query is executed in both cases identically.

Any help or experience would be greatly appreciated. Thank you for your time!

1
  • Try this: var queryString1 = $"SELECT * FROM Product_Table WHERE CustomerInvoice='{customerInvoiceSelected}';"; Commented Oct 26, 2018 at 13:32

1 Answer 1

5
CustomerInvoice='@custInvSel';";

needs be

CustomerInvoice=@custInvSel";

when you parameterizing, you don't add quotes to string, etc. You just send raw data. And don't add semicolon.

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

1 Comment

That's it. I knew it had to be something simple with syntax. Much appreciated!

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.