sql commnd query stringshttp://forums.asp.net/t/1798201.aspx/1?sql+commnd+query+stringsSun, 29 Apr 2012 18:31:04 -040017982014956955http://forums.asp.net/p/1798201/4956955.aspx/1?sql+commnd+query+stringssql commnd query strings <p>hi everyone. can someone tell me whether the sql command is right because i get a blank gridview when i click the search button. The button was supposed to search the keywords entered in a textbox from 2 tables using wildcards. thank you in advance</p> <pre class="prettyprint">Private Sub bnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bnSearch.Click Dim myConnection As New SqlConnection(myConStr) Dim mySqlCommand As New SqlCommand() Dim mySqlDataReader As SqlDataReader Dim keywords As String Dim sqlStr As String keywords = &quot;'%'&quot; &amp; txtSearch.Text sqlStr = &quot;SELECT tblBooks.fldTitle, tblBooks.fldAuthor, tblBooks.fldISBN, tblBooks.fldNoCopies, tblBooks.fldInStock, tblCat.fldCatName FROM tblBooks INNER JOIN tblCat ON tblBooks.fldCatID = tblCat.fldCatID WHERE (fldTitle LIKE @keywords) AND (fldAuthor LIKE @keywords) AND (fldCatName LIKE @keywords) AND (fldISBN LIKE @keywords)ORDER BY tblBooks.fldTitle&quot; mySqlCommand.Parameters.AddWithValue(&quot;@keywords&quot;, keywords) mySqlCommand.Connection = myConnection mySqlCommand.CommandText = sqlStr myConnection.Open() mySqlDataReader = mySqlCommand.ExecuteReader gvBookList.DataSource = mySqlDataReader gvBookList.DataBind() End Sub</pre> <p><br> <br> </p> 2012-04-29T13:35:09-04:004957002http://forums.asp.net/p/1798201/4957002.aspx/1?Re+sql+commnd+query+stringsRe: sql commnd query strings <p>Hi,</p> <p>Try:</p> <pre class="prettyprint">keywords = &quot;%&quot; &amp; txtSearch.Text &amp; &quot;%&quot;</pre> <p></p> <p>Hope this helps.</p> <p>&nbsp;</p> 2012-04-29T14:46:38-04:004957014http://forums.asp.net/p/1798201/4957014.aspx/1?Re+sql+commnd+query+stringsRe: sql commnd query strings <p>You try with like &nbsp;%youText%</p> 2012-04-29T14:58:11-04:004957120http://forums.asp.net/p/1798201/4957120.aspx/1?Re+sql+commnd+query+stringsRe: sql commnd query strings <pre class="prettyprint">keywords = txtSearch.Text sqlStr = &quot;SELECT tblBooks.fldTitle, tblBooks.fldAuthor, tblBooks.fldISBN, tblBooks.fldNoCopies, tblBooks.fldInStock, tblCat.fldCatName FROM tblBooks INNER JOIN tblCat ON tblBooks.fldCatID = tblCat.fldCatID WHERE ((fldTitle LIKE '%'&#43; @keywords&#43;'%') Or (fldAuthor LIKE '%'&#43; @keywords&#43;'%') Or (fldCatName LIKE '%'&#43; @keywords&#43;'%') Or (fldISBN LIKE '%'&#43; @keywords&#43;'%' ) ) Or (@keywords IS NULL) ) ORDER BY tblBooks.fldTitle &quot;</pre> <p></p> 2012-04-29T18:31:04-04:00