G
Guest
Hi everyone,
I'm trying to use a select command as the CommandText of an ADO.NET
SQLCommand object (I'm using SQL Server as the database). From the Query
Analyzer I can run the query and get the correct result, but in my program,
the command using this query returns no rows.
My code looks like this...
Private Const availFutureRes = "SELECT Id from AlcResIndx WHERE ResType IN
('PF','PW') " & _
"AND Date <= @Date AND SKU LIKE @SKU AND HasBalance = 'Y' " & _
"ORDER BY Date DESC"
Dim dr as SqlDataReader
Dim cn As SqlConnection = New SqlConnection(connectStr)
Dim cmd As SqlCommand = New SqlCommand(availFutureRes, cn)
cmd.Parameters.Add("@Date", SqlDbType.DateTime, 8, "Date")
cmd.Parameters.Add("@SKU", SqlDbType.Char, 18, "SKU")
cmd.Parameters("@Date").Value = r.StartDate
cmd.Parameters("@SKU").Value = RTrim(key) & "%"
cn.Open()
Try
dr = cmd.ExecuteReader()
So what's wrong with this? I've tried setting up the "@SKU" value so that
it's enclosed in single quotes (like it would be in the Query Analyzer like
'AA127%'). Didn't help.
Any help is appreciated.
BBM
I'm trying to use a select command as the CommandText of an ADO.NET
SQLCommand object (I'm using SQL Server as the database). From the Query
Analyzer I can run the query and get the correct result, but in my program,
the command using this query returns no rows.
My code looks like this...
Private Const availFutureRes = "SELECT Id from AlcResIndx WHERE ResType IN
('PF','PW') " & _
"AND Date <= @Date AND SKU LIKE @SKU AND HasBalance = 'Y' " & _
"ORDER BY Date DESC"
Dim dr as SqlDataReader
Dim cn As SqlConnection = New SqlConnection(connectStr)
Dim cmd As SqlCommand = New SqlCommand(availFutureRes, cn)
cmd.Parameters.Add("@Date", SqlDbType.DateTime, 8, "Date")
cmd.Parameters.Add("@SKU", SqlDbType.Char, 18, "SKU")
cmd.Parameters("@Date").Value = r.StartDate
cmd.Parameters("@SKU").Value = RTrim(key) & "%"
cn.Open()
Try
dr = cmd.ExecuteReader()
So what's wrong with this? I've tried setting up the "@SKU" value so that
it's enclosed in single quotes (like it would be in the Query Analyzer like
'AA127%'). Didn't help.
Any help is appreciated.
BBM