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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass parameter in sql statement 1

Status
Not open for further replies.

taree

Technical User
May 31, 2008
316
US
I am getting an error message. I am just wondering if this is even possible. please let me know if there is a better way to handle this. thank you

SqlDataSource1.SelectCommand &= " AND (p.datepur BETWEEN to_date:)MinValue1, 'MM-DD-YYYY') AND to_date:)MaxValue1, 'MM-DD-YYYY'))"
SqlDataSource1.SelectParameters.Add(":MinValue1", minComb1)
SqlDataSource1.SelectParameters.Add(":MaxValue1", maxComb1)
 
First, DON'T use the datasource controls. They are not flexable and cause more programming issues than they solve.
Second, it looks like you are writing an Oracle query, not a sql server query, so you will get errors.

My suggestion, write a stored procedure with parameters.
 
or use an ORM (object relational mapper) framework like SubSonic, WilsonORMapper, ActiveRecord, NHibernate.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thank you Guys for the help. I was just asked to do a quick fix and now is working fine. Before I had the data type for both variable as string and change that to date data type and works fine. I will look into your suggestion and see they are going to be receptive to that.

Dim minComb1 As Date = minMonth & "/" & minDate & "/" & minYear
Dim maxComb1 As Date = maxMonth & "/" & maxDate & "/" & maxYear

SqlDataSource1.SelectCommand &= " AND (p.datepur BETWEEN to_date:)MinValue1, 'MM/DD/YYYY') AND to_date:)MaxValue1, 'MM/DD/YYYY'))"
SqlDataSource1.SelectParameters.Add(":MinValue1", minComb1)
SqlDataSource1.SelectParameters.Add(":MaxValue1", maxComb1)
 
there is an inverse relationship to the use of MS RAD development wizards and the maintainability of the system.

case in point your webform is talking directly to the database. the webform should have no knowledge of the database. it should delegate the responsibility to another object. (controller > service > repository) for more information on this methodology of design research the concept Domain Driven Design.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top