Search on ASP Classic - asp-classic

I have this problem on my search page . For example on my search page I have this data on a table
01234567
24567801
on my search if i type 01, that 2 record appear what i want is for the
01234567 to only appear. How can i get this result?
this is the code I have on my search page:
dim search
search = ""
if tsearch <> "" then
if len(trim(tsearch)) <> 0 then
search= " AND (NUMBER_LiSt LIKE '%" & tsearch & "%')"
end if
end if

#Vogel612 is correct that the LIKE is looking for any instance of '01' in the NUMBER_LIST items, as you have the wildcard symbols (%) at the beginning and end of the LIKE.
If you are looking only for numbers that start with tsearch (eg: '01') then remove the '%' at the start of the tsearch:
search= " AND (NUMBER_LiSt LIKE '" & tsearch & "%')"
Similarly, to look for only numbers that end in tsearch, add the starting, and remove the trailing '%':
search= " AND (NUMBER_LiSt LIKE '%" & tsearch & "')"
Other than LIKE there are other SQL Commands for searching (like MSSQL's PATINDEX) but they are more tricky that a good LIKE.

Related

vb.net string concat adds vbCrlf literal to the string

I am trying to build a string that includes a newline character and is getting the weirdest result. This string is going to be stored in a SQL database to be later used as part of an email. My code is the following:
Dim strBody As String = "Andy," & Environment.NewLine
When I inspect the value of strBody during a debugging session, it is the following:
"Andy," & vbCrlf
I am obviously expecting is to be more like:
"Andy,"
Knowing that what is after the , is a hidden character.
Ultimately, the problem is... when I include strBody as part of my SQL insert statement, it literally shows up as the following within my SQL insert statement:
'Andy," & vbCrLf & "'
I was using this code yesterday and it worked fine. I am using similar code within another function of the same asp.net project and it works fine. I have tried using + instead of &, I have tried to use vbCrLf instead of Environment.NewLine, I have tried using stringbuilder, I have tried using string.concat. All with the same results where the & vbCrLf is included in strBody.
Is there a setting that I accidentally changed?
I know this is a weird one... Any help is greatly appreciated.
This is only Visual Studio showing you that there is new line character (vbCrLf or Environment.NewLine). If you use that string anywhere, it will be stored correctly.
I believe you will need to use some combination of Char(10) and Char(13):
Dim strBody As String = "'Andy,'" & " + CHAR(13)+CHAR(10) + "
There is a discussion about these and other methods on this thread.
You can do like this if you just need to insert Environment.NewLine inside database.
Dim a As String = """ & Environment.NewLine & """
Dim strBody As String = String.Format("Andy,{0}", a)
'"Andy," & Environment.NewLine & ""

Visual Basic code from Microsoft Access does not work

Private Sub cmdAdd_Click()
'add data to table
CurrentDb.Execute "INSERT INTO Products(ProductCode, ProductName, Category, UnitPrice, UnitCost, QuantityInStock, SupplierCode) " & _
" VALUES (" & Me.txtProductCode & " , '" & Me.txtProductName & "' , '" & Me.cboCategory & "' , '" & Me.txtUnitPrice & "' , '" & Me.txtUnitCost & "' , '" & Me.txtQuantityInStock & "' , '" & Me.cboSupplierCode & "')"
'refresh data on list of form
ProductsSub.Form.Requery
End Sub
the code above is suppose to record the data that has been input from the interface, but it does not do anything. The same format of code was used in a different form and it worked. Really weird, but i don't how it was possible.
You'll need to debug this. One of the values you are referencing visa the Me object is not resolving. Place a breakpoint on the CurrentDB.Execute command, and hover over each Me reference (i.e. Me.txtProductCode) to make sure it is obtaining the correct value for the insert. If you have moved this to a library, you may want to use CodeDB.Execute instead of CurrentDB.Execute. I would also check the table to see if the actual INSERT is working as there may be an issue with the Requery event.

Entering each row of datagrid into SQL database

I'm attempting to take a column from each row of my datagrid and enter it into an SQL database. Having all sorts of problems/errors making it work.
This is the most current version:
For i = 0 to agentGridView.Rows.Count - 1
varAgt = agentGridView.Rows(i).Cells(1).Text
strSQL = "INSERT INTO tblAgentVisitAgents (VisitID, AgtID)" & _
" Values (" & _
VisitID.Text & "," & _
varAgt & ")"
strSQL = Utils.replaceChars(strSQL)
DAL.ExecNonQuery(strSQL, CommandType.Text)
Next
EDIT: The issue is that my cell(1) is a hidden field. When I make it visible, the entry form works. When it's hidden, it won't enter anything and thus gives me a syntax error. Is there a way I can use a hidden field for entry purposes?
You need to use Text instead of Value . Like following.
varAgt = agentGridView.Rows(i).Cells(1).Text instead of varAgt = agentGridView.Rows(i).Cells(1).Value
But if you have that control in a Label, then you need to typecast to label and then use Text. E.g.
varAgt = CType(agentGridView.Rows(i).Cells(1).FindControl("controlID"),Label).Text -- replace controllID with required label id.
Source - http://www.aspsnippets.com/Articles/How-to-get-Selected-Row-cell-value-from-GridView-in-ASPNet.aspx
Here's what I went with:
Front:
<asp:GridView ID="agentGridView" DataKeyNames="agentName,agentValue" ... />
Back:
For i = 0 to agentGridView.Rows.Count - 1
varAgt = agentGridView.DataKeys(i).Values("agentValue").ToString
strSQL = "INSERT INTO tblAgentVisitAgents (VisitID, AgtID)" & _
" Values (" & _
VisitID.Text & "," & _
varAgt & ")"
strSQL = Utils.replaceChars(strSQL)
DAL.ExecNonQuery(strSQL, CommandType.Text)
Next
Source (for C#): Hide BoundField's but still be able to get values with C#

comparing two different gridview's selected value

Hello I have threegrid views with the select row enabled. The user will select an item from each grid view then on selected index change the values will be compared to the other two gridviews to see if they are equal. While debugging I can see that they are the same so I'm not sure why the if statement is always passing as true. Is it possibly comparing the indexes? Thanks for the help!
If gvCustomer.SelectedValue IsNot gvSiteAddress.SelectedValue Then
dataSourceGVCust.SelectCommand = ConfigurationManager.AppSettings("SelectCustomer") & " WHERE CUST_NO LIKE '%" & gvSiteAddress.SelectedValue.ToString & "%' ORDER BY CUST_NAME"
End If
If gvJobNumber.SelectedValue IsNot gvSiteAddress.SelectedValue Then
dataSourceGVJobNumber.SelectCommand = ConfigurationManager.AppSettings("SelectJobNumber") & " WHERE CUST_NO LIKE '%" & gvSiteAddress.SelectedValue.ToString & "%' ORDER BY JOB_NO"
End If
You're misusing the IsNot operator. See http://msdn.microsoft.com/en-us/library/t3bat82c.aspx
IsNot does a reference equals. That is, are the two objects PHYSICALLY pointing to the same instance of an object -- not just do they have the same value.
Change IsNot to <> and you should be back in action.
EDIT: A cast to the proper type is likely required. For example, if your values are a numeric ID then something like:
If CType(gvJobNumber.SelectedValue, Integer) <> CType(gvSiteAddress.SelectedValue, Integer) Then
Or if String then substitute String where you see Integer above.

Classic ASP: Execute 2 Update Statements in single function

I am writing Classic ASP program.In one function, I have to use 2 update statements to one table in one function. First Statement is update the quantity of invoice and second update statement is base on that update Purchase Order quantity and Purchase Requisition quantity, I need to update one flag field. Can I write in same function as following:
SET RS = app.Execute("SELECT PRInvoiceNo, Quantity FROM PurchaseOrderDetails WHERE CoID='" & param & "'")
do while RS.EOF=false
app.Execute("UPDATE PurchaseRequisitionDetails SET PO_Quantity = PO_Quantity + " & RS("Quantity") & " WHERE CoID='" & param & "' AND PRInvoiceNo = '" & RS("PRInvoiceNo") & "'")
app.Execute("UPDATE PurchaseRequisitionDetails SET FullyPaidFlag=CASE WHEN PO_Quantity >= Quantity THEN 1 ELSE 0 END WHERE CoID='" & param & "' AND PRInvoiceNo = '" & RS("PRInvoiceNo") & "'")
RS.MoveNext
loop
The problem is in the loop the first statement is properly worked. Second one not work. What can it be? Can I do like this or not?
Well, I have to go, but be sure to check the following:
Response.Write(RS.RecordCount) -- are there any records? Or, do a Response.Write("hello") inside the loop to make sure.
Check that RS("Quantity"), param, etc are not null. If they are, your string concatenation will result in a null string.
Also, please, please don't forget to escape your variables!
Replace(param, "'", "''")
Good night!

Resources