Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello friends. Thank you for your suggestion in my previous questions.

In order to query some result out of DB inside a time period, I typed this code:

Dim strSQL As String = "Select * From ScheduleView where schStartTime
between '"
      strSQL = strSQL & StartDay
      strSQL = strSQL & "' and '"
      strSQL = strSQL & EndDay
      strSQL = strSQL & "' order by hId,schStartTime ; Select * From
HomeHelper order by hId"

which "StartDay" & "EndDay" is 2 DateTime variable. Although it works well for my program... I think there must be some more clever way to do it out. If the way do exist please give me some idea. Thank you.

Posted

If the string concatenation code is really your concern (rather than db programming efficiency w/c has been addressed by Plaus' reply), using String.Format may make your code look neater:

 

Dim strSQL As String = String.Format("Select * From ScheduleView where schStartTime between '{0}' and '{1}' order by etc...", StartDay, EndDay)

  • Administrators
Posted
Personally I'd always opt for stored procedures whenever the DB provides the capability. String concatenation (or its variants like String.Format) leave you open to potential security flaws and can increase the amount of validation you need to perform (search for phrases like SQL Injection to see what I mean).

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • 2 weeks later...
Posted

I may be wrong, but why use strings?

 

SELECT * FROM ScheduleView WHERE

DateDiff( day, StartDate, schStartTime ) > 0 AND DateDiff( day, schStartTime, EndDate ) > 0

ORDER BY hID, schStartTime

IN PARVUM MULTUM

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...