?
Solved

AddWithparameter for this query

Posted on 2010-01-04
3
Medium Priority
?
280 Views
Last Modified: 2012-05-08
Hi all,
I have gridview to fill with customers.The User keys in the customer name in the search textbox.Depending on that , search is made on the customer and fill the gridview.When the user type customer with Apostrope( Adc's), i get an error. i know the mistake, I have to use  addwith parameter.
Please help to do so.. My brain has a freeze as the temp here are dipping

     
selectQuery = "Select Customers.Customerid,Customers.Companyname As Company,Customers.City,StateProvince.Countryregionname as Country from Customers,Stateprovince where Customers.Stateprovinceid=StateProvince.Stateprovinceid And Companyname LIKE '" & alphabet & "%' order By Companyname ASC"
 Dim ad As New SqlDataAdapter(selectQuery, MyConn)

        Dim DS As New DataSet()
        ad.Fill(DS)
        If ds.Tables(0).Rows.Count > 0 Then
            GrdCustomer.DataSource = DS
            GrdCustomer.DataBind()
        End If

Open in new window

0
Comment
Question by:SaraDob
3 Comments
 
LVL 14

Expert Comment

by:Emes
ID: 26173028
try using two '
 so use Adc''s
0
 
LVL 25

Accepted Solution

by:
DBAduck - Ben Miller earned 2000 total points
ID: 26173047
That should help you.

selectQuery = "Select Customers.Customerid,Customers.Companyname As Company,Customers.City,StateProvince.Countryregionname as Country from Customers,Stateprovince where Customers.Stateprovinceid=StateProvince.Stateprovinceid And Companyname LIKE @varLike order By Companyname ASC" 
Dim adCmd as New SqlCommand(selectQuery, MyConn)
adCmd.Parameters.Add("@varLike", SqlDbType.VarChar, 100).Value = alphabet & "%"

Dim ad As New SqlDataAdapter(adCmd) 
 
        Dim DS As New DataSet() 
        ad.Fill(DS) 
        If ds.Tables(0).Rows.Count > 0 Then 
            GrdCustomer.DataSource = DS 
            GrdCustomer.DataBind() 
        End If

Open in new window

0
 
LVL 1

Author Closing Comment

by:SaraDob
ID: 31672512
Thanks for Quick Perfect reply
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question