Sunday, February 19, 2012

c# and SQL query

Using Visual Studio 2005 c#

I am trying to create a query to one of my tables in my database. It looks something like this-

SELECT ...

FROM ...

WHERE TranDetail.EndDateTime = TranHeader.EndDateTime

Now that works fine... but i need to make another query... that would look something like this.

SELECT...

FROM...

WHERE TranDetail.EndDateTime = serial.

Serial is a variable in my current c# coding. I know in other languages they use stuff like ':' or'@.'.. but i dont know how to do this in c#.

you can use parameterized query. set your comment text as
SELECT...FROM...WHERE TranDetail.EndDateTime = @.serial
and

Command.Parameters.Add("@.serial", yourC#Variable);
You have to make sure type is match.

Hope this help

No comments:

Post a Comment