Results 1 to 4 of 4

Thread: Concatenating SQL statements in VB.NET

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2003
    Posts
    3

    Angry Concatenating SQL statements in VB.NET

    I am trying to type the SQL query statements in the code for a Order entry application, so that the query will execute at runtime instead of just typing it directly into the data adapter at design time. The runtime SQL worked for integers, but I am having a hard time concatenating the SQL statement properly to search for text. Does anyone happen to know anything about the concatenation for that? I'd greatly appreciate any advice you all could give us. Thanks!


    Also, were is the code for a search button that searches a database called customers. In Bold is the problem we are having.

    Private Sub frmFinalProject_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    mstrQuery = "SELECT CustNo, CustName, AddrZip, AddrStreet, AddrState, AddrCity FROM Cust "


    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    Dim bull**** As String

    If txtCustName.Text = "" Then

    Else
    DsCustomer1.Clear()
    dbCustomer.SelectCommand.CommandText = mstrQuery & "WHERE CustName = " & txtCustName.Text
    dbCustomer.Fill(DsCustomer1)



    End If

    txtCustNo.Text = cbocustno.Text

    End Sub

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    You might wanna add speech marks round the field, it is text after all. Also, watch your "like" statement, using SQL directly you have to use a % instead of a * , like (o the gag) you would in MS-Access.

    & "WHERE CustName = '" & txtCustName.Text & "'"

  3. #3
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I'd suggest using parameters - much easier to write and read the code.

  4. #4
    Addicted Member MasterBlaster's Avatar
    Join Date
    Jul 2002
    Location
    Seattle
    Posts
    196
    USE PARAMETERS!! If you don't know how ask. I will be more than happy to post the code.
    Last edited by MasterBlaster; Dec 8th, 2003 at 07:40 PM.
    "And most of the evils of society can, in fact, be cured through information. We have a society that has been disinformed and based on the disinformation has made irrational choices. And that's what I mean by 'ignorance.' People, who ordinarily might be smart, are deprived of the data by which to make a rational decision, don't have the data to do it."
    Frank Zappa

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width