November 21, 2007 at 8:51 am
select EMPLNO,[Full Name],[CCNAME],[CC] from HREMP where [Full Name] like '%" & strS & "%' and [CC] like '01032%' and (EMPSTATUS <> 90 or EMPSTATUS is null) order by [Full NAME];"
If end user enter strS= O'CONNELL, it will give me error .
how to solve the problem ?
Thx.
November 21, 2007 at 5:04 pm
select EMPLNO,[Full Name],[CCNAME],[CC] from HREMP where [Full Name] like '%" & REPLACE(strS,'''','''''') & "%' and [CC] like '01032%' and (EMPSTATUS <> 90 or EMPSTATUS is null) order by [Full NAME];"
--Jeff Moden
Change is inevitable... Change for the better is not.
November 26, 2007 at 2:51 am
Replace single quotes with double singlequotes.
November 26, 2007 at 6:35 am
I tried that before. While I bulit the vb.net application. it gave me error.
strS=Replace(strS,'''',''""")
it has bulit error. expression expression expected.
if I put strS with replace in my string like Jeff M. did. it gave me green. like comment out that line.
Thx.
November 26, 2007 at 6:55 am
The code which Jeff has posted is for T-SQL and not for VB. T-SQL uses single quotes to delimit strings (can be changed with QUOTED IDENTIFIER set option) whereas VB uses double quotes.
Replace with this
strS=Replace(strS,"'","''")
But what if somebody puts up % in the name:hehe:?
--Ramesh
November 26, 2007 at 7:02 am
but the outcome did not come out as I expected.
select EMPLNO,[Full Name],[CCNAME],[CC] from HREMP where [Full Name] like '%O''CONNELL%' and [CC] like '01032%' and (EMPSTATUS <> 90 or EMPSTATUS is null) order by [Full NAME];"
I have O'Connell in the database. it did not show up at all.;)
November 26, 2007 at 7:38 am
Ok... are we working in VB or T-SQL???
And, please provide a sample of the input that you currently have that is not being transformed to your liking as well as what you would like it to look like. Without such a before/after sample, we're really only guessing.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 26, 2007 at 11:32 am
It is vb.net code , here.
in the vb.net
I have select statement
select EMPLNO,[Full Name],[CCNAME],[CC] from HREMP where [Full Name] like '%" & REPLACE(strS,'''','''''') & "%' and [CC] like '01032%' and (EMPSTATUS <> 90 or EMPSTATUS is null) order by [Full NAME];
if end user key in the text box O'Connell.
I am expecting all the records with O'Connell come out
'fill the data with the same last name
Dim NameComm As New SqlCommand()
NameComm.Connection = myConn
myConn.Open()
Dim strComm As String
'it may need to modify which only have cc with 03
Dim strS As String
strS = txtName.Text.Trim.ToUpper
strS = Replace(strS, "'", "''")
strComm = "select EMPLNO,[Full Name],[CCNAME],[CC] from HREMP where [Full Name] like '%" & strS & "%' and [CC] like '01032%' and (EMPSTATUS <> 90 or EMPSTATUS is null) order by [Full NAME];"
NameComm.CommandText = strComm
NameComm.CommandType = CommandType.Text
Dim NameReader As SqlDataReader
Try
NameReader = NameComm.ExecuteReader
Catch ex As Exception
Response.Write(ex.ToString)
End Try
lstName.Items.Clear()
Dim strName As String ' the name show in the list box
Try
While NameReader.Read
strName = NameReader("Full Name") & ControlChars.Tab & NameReader("CCNAME") & ControlChars.Tab & NameReader("CC")
lstName.Items.Add(New ListItem(strName, NameReader("EMPLNO")))
End While
If lstName.Items.Count = 0 Then
Me.lblLoginError.Visible = True
Me.lblLoginError.Text = "Check the last name you just entered"
End If
Catch ex As Exception
Response.Write(ex.ToString)
End Try
November 26, 2007 at 11:55 am
.NET syntax for replace is
<name of string object>.REPLACE("old value", "new value")
So you want
Dim strS As String
strS = txtName.Text.Trim.ToUpper
strS.Replace("'", "''")
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
November 26, 2007 at 12:10 pm
Thx. It worked fine right now.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply