1

I am doing this query in a stored procedure: SELECT TOP 1 [Employe] FROM Transactions WHERE [Employe]=@Name AND Date=@Date

It is supposed to return an employee ID (int). In my application (ASP.NET C#) I get this error when, with a DataReader, I read a line: *Conversion failed when converting the varchar value * to data type int. *

What exactly is the type * ? And I am not trying to convert anything.

2
  • I'd like to see more code, please. The procedure's code, and also how you're executing the DataReader. Is Employe spelled right? Commented Feb 14, 2012 at 17:01
  • Typically that error shows the data contained in the varchar value that is being used. In this case, somewhere it thinks a * is present. We may need more code and what's in the database to properly help with that issue. Commented Feb 14, 2012 at 17:02

3 Answers 3

3

Looks like you're sleecting the Employe column which I'm guessing is varchar. I'm assuming you want to select the ID column.

SELECT TOP 1 [ID] FROM Transactions WHERE [Employe]=@Name AND Date=@Date
Sign up to request clarification or add additional context in comments.

1 Comment

He may also want to do WHERE [Employe] LIKE Name and not = Name, since it also looks like Name contains a '*'
0

Most likely you are passing @Name parameter as a varchar where Employe field is an int field.

Or you could be trying to assign your resulting value of Employe to an int datatype then you would be seeing this error.

Please post your Transactions table definition and your stored procedure code to further troubleshoot.

Comments

0

I think probably your @Name parameter is specified as an VARCHAR, but the Employe field in the table is an INT field.

Try this:

SELECT TOP 1 [Employe] FROM Transactions WHERE CAST([Employe] AS VARCHAR)=@Name AND Date=@Date

1 Comment

Thanks for all your answers! Just figured out what my error was: I declared my @Name parameter as a varchar in my stored procedure and entered a int I my C# code. N00b error, I know!

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.