Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using where statement with sqldependency?

Status
Not open for further replies.

jrenae

Programmer
Jan 18, 2006
142
US
Hello,

We have a service that is kicked off by a sqldependency notification. The query associated with the command object is selecting all id's from a table, which is working fine, except I really don't want the service to fire unless a record is inserted that has a certain status. So I would like to add a where statement to the query. Is that allowed? Can I change the query from this:
Code:
SELECT LeadDeliveryLog.LeadDeliveryLogID FROM dbo.LeadDeliveryLog
to this?
Code:
SELECT LeadDeliveryLog.LeadDeliveryLogID FROM dbo.LeadDeliveryLog Where LeadDeliveryLog.Status = 'rejected'


Thanks in advance

 
Unless I'm missing something, yes you can. It sounds like SQL Injection is not a worry here, but you might still want to consider using parameters to make your query more flexible (there are slight performance gains to be had here as well).

Code:
using (System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("SELECT LeadDeliveryLog.LeadDeliveryLogID FROM dbo.LeadDeliveryLog Where LeadDeliveryLog.Status = @status", connection))
{
    command.Parameters.Add("@status", System.Data.SqlDbType.VarChar).Value = "rejected";
    System.Data.SqlClient.SqlDataReader reader = command.ExecuteReader();
    if (reader.Read())
    {
        //do some stuff
    }
}

}

[small]----signature below----[/small]
The author of the monograph, a native of Schenectady, New York, was said by some to have had the highest I.Q. of all the war criminals who were made to face a death by hanging. So it goes.

My Crummy Web Page
 
Thank you...It did work with the where clause I entered above. No worry about sql injection as it's only an internal app using it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top