|
-
Dec 8th, 2003, 03:31 PM
#1
Thread Starter
New Member
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
-
Dec 8th, 2003, 03:39 PM
#2
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 & "'"
-
Dec 8th, 2003, 04:04 PM
#3
Frenzied Member
I'd suggest using parameters - much easier to write and read the code.
-
Dec 8th, 2003, 07:31 PM
#4
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|