Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  String concatenating for Dataset.compute method (Tuesday, December 21, 2004)




Found the following interesting discussion in the Newsgroups:

String concatenating for Dataset.compute method
by:Anonymous

I am trying to use the compute method on a dataset that uses a concatenated string as the filter. Here is my code:

Dim myTable As DataTable
myTable = CheckHrsVacDataSet1.Tables("PYCheckHistory")
Dim str1 As String = "((Employee = '"
Dim str2 As String = "') AND (CheckDate >= '"
Dim str3 As String = "'))"
VacHrsThisYr.Text = myTable.Compute("Sum(TotalVacationHrs)", (String.Concat(str1, EmployeeID, str2, fiscalYrDate, str3))).ToString

The code works fine but I get an error when my str1 picks up employees with an apostrophe in their name (ie: O'neal). The compute method thinks that the O' is the end of the string. Does anyone know how I can code around this?

Thanks



 Reply:
by:Jay B. Harlow [MVP - Outlook]

 JC,
You need to "quote" the quoted string.

The easiest way is to use String.Replace, something like:

VacHrsThisYr.Text = myTable.Compute("Sum(TotalVacationHrs)",
String.Concat(str1, EmployeeID.Replace("'", "''"), str2, fiscalYrDate,
str3))

Note String.Concat & String.Replace return strings, there is no need to call
ToString on the return value.

Hope this helps
Jay


 Reply:
by:Anonymous

 thanks jay, u got it


 Reply:
by:mwazir

 Have you tried replacing one apostrophe with two?

EmployeeID = EmployeeID.Replace(Chr(39), Chr(39) & Chr(39))
VacHrsThisYr.Text = myTable.Compute("Sum(TotalVacationHrs)",
(String.Concat(str1, EmployeeID, str2, fiscalYrDate, str3))).ToString

HTH

--
Wazir








0 Comments:

Post a Comment

 
Previous Posts
    - Any VB/COM experts here??
    - The specified domain either does not exist or coul...
    - Measuring an angle
    - Unable to upgrade VB6 COM Dll to VB.Net
    - TypeConverter.CreateInstance-Method
    - vb.net & word
    - How to let GUI application write output to command...
    - Copy object with .Net?
    - Find the cursor position in a textbox
    - Extracting Image Metadata

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006

Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland