Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Abid
110 Posts |
Posted - 2013-04-03 : 12:11:24
|
HI. I have a helping form, which appears on the leave event of the textbox from main form (SaleInfo). When this form is loaded so the Prod_Name from ProdInfo is loaded into Combobox (where combobox is set to AutoComplete).On the form there is a button on which i have the following Query:Dim selProd As String = "select * from ProdInfo where Prod_Name like '%" & ComboBox1.Text & "%'"I want to load only that product into a DataGridView on the same helping form, which is select in Combobox. But when i press the button so it displays the entire table values. Please tell me that what is wrong with this query. |
|
chadmat
The Chadinator
1974 Posts |
Posted - 2013-04-03 : 12:17:42
|
Set a breakpoint on that line and make sure ComboBox1.Text is what you expect it to be.-Chad |
|
|
Abid
110 Posts |
Posted - 2013-04-03 : 21:34:21
|
yes i put a breakpoint on my query. When the break point occurs, so its equal to nothing. But then i put the breakpoint on the next line, right after the query, i.e. Dim selProd As String = "select * from ProdInfo where Prod_Name like '%" & ComboBox1.Text & "%'" Dim cmdSql As New SqlCommand(selProd, cnSql) cmdSql.CommandType = CommandType.Text daSql.SelectCommand = cmdSql daSql.Fill(dsSql, "ProdInfo") dgvSalesPicker.DataSource = dsSql dgvSalesPicker.DataMember = "ProdInfo" This is what it appears in breakpoint.selProd = "select * from ProdInfo where Prod_Name like '%Keyboard%'" |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2013-04-04 : 00:48:22
|
quote: Originally posted by Abid Please tell me that what is wrong with this query.
Apart from the SQL injection and performance issue you mean? |
|
|
Abid
110 Posts |
Posted - 2013-04-04 : 05:41:21
|
Apart from SQL Injection. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-04 : 06:07:28
|
are you looking at pattern serach or exact search? ie do you want records having word Keyboard in their name or do you want only keyboard record's detail?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Abid
110 Posts |
Posted - 2013-04-04 : 08:28:25
|
This time i need only exact search.But it would extremely applausable if you guide me for both. |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2013-04-04 : 12:51:30
|
The way it is now, you should be getting anything that contains the word "Keyboard". If you want exact match, change LIKE '%Keyboard%'to='Keyboard'-Chad |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-04 : 14:29:10
|
quote: Originally posted by Abid This time i need only exact search.But it would extremely applausable if you guide me for both.
if you want exact search the statement should beDim selProd As String = "select * from ProdInfo where Prod_Name = '" & ComboBox1.Text & "'" ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Abid
110 Posts |
Posted - 2013-04-06 : 05:37:21
|
I think the problem is with, not clearing the DataSet. I'm just clearing the dataSet so the problem is solved. |
|
|
|
|
|