Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi all!!

i have taken a string variable and i am adding some query to it. the problem that i am facing is that the variable shows only the first string and not the second string , it should show both the strings.

SQL
If monthNo = j Then
                   Dim string1 As String = ""
                   string1 = "Select sanctioned_amt from details_gpf_advance_employee where empid=" + eid + "  and "
                   string1 += "DatePart(Month, sanction_order_dt) = " + j + ""
                   sanctioned_amt = Dal.ExScalar(string1)
               End If


i used break points to find the the text. String1 int the third line shows the same text as in front of it but string1 in 5th line also shows the same text as that of string1 in third line. It should show both the text but it's not showing.. Please help me find the problem.

problem is with the
"DatePart(Month, sanction_order_dt) = " + j + ""
part. It's showing "" when seen using breakpoint
Posted
Updated 11-Jun-12 1:54am
v2

Your query like this

SQL
Dim string1 As String = ""
                  string1 = "Select sanctioned_amt from details_gpf_advance_employee where empid=" + eid + "  and "
                  string1 += "DatePart(Month, sanction_order_dt) = " + j + ""
                  sanctioned_amt = Dal.ExScalar(string1)


Write like this

SQL
Dim string1 As String 
                 string1 = "Select sanctioned_amt from details_gpf_advance_employee where empid=" + eid + "  and "
                 string1 += "DatePart(Month, sanction_order_dt) = " + j + ""
                 sanctioned_amt = Dal.ExScalar(string1)


Now it will work

Thanks,
SP
 
Share this answer
 
Comments
nagasiva 11-Jun-12 8:05am    
Good 5+
Use "&=" for strings:
VB
string1 &= String.format("DatePart(Month, sanction_order_dt) = {0}",j)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900