on 07-30-2005 8:07 AM
Dear All,
I can't use value of combo Box in where condition of data adapter in coding. How do i do? please help me! I want to use where condition form selected value of combo Box. I write as follow but run time error is appear.
dim sSQL as string
sSQL = "SELECT ProductID, ProductName, SupplierID, CategoryID, UnitPrice FROM Products Where CategoryID= " & cboCategory.SelectedValue & " "
Dim daProducts As New SqlDataAdapter(sSQL, con)
dim dsProducts as DataSet
dsProducts.Clear()
daProducts.Fill(dsProducts, "Products")
Thanks and best regards,
znp
Hi Zin,
The problem is not with the combo box value, you are not providing correct parameters to the data adapter.
Please try the following code:
dim con as new SqlConnection
con.ConnectionString = "<u>Give the connection string for ur SQL server here</u>";
con.Open()
dim cmd as new SqlCommand
cmd.Connection= con
cmd.CommandText = "SELECT ProductID, ProductName, SupplierID, CategoryID, UnitPrice FROM Products Where CategoryID= " & cboCategory.SelectedValue
Dim daProducts As New SqlDataAdapter(cmd, con)
dim dsProducts as New DataSet
dsProducts.Clear()
daProducts.Fill(dsProducts, "Products")
Hope this helps. Get back to me in case you still face the problem.
Regards,
Ankit Bhansali
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Zin,
I am not very clear with the question.
I guess you are trying to print the content of the row. Try typecasting it to string like ds.tables(0).rows[0][0].ToString().
Just try doing this, in case u still have a problem, let me see the sanpshot of the code. That will give me a clear idea of what you are trying to do.
Regards,
Ankit Bhansali
Dear Ankit Bhansali,
I want to filter the select command. Now i'm select one Category Name in Combo Box, In DataGrid related Product of that Category. Can u help me. I want to write this in code. i don't want to use tool. I success this using with tool.
Thanks and best regards,
znp
Message was edited by: Zin Nwe Phyo
Dear Zin,
I am not clear with your question. Are you trying to just get the Product ID and Product name as the result and bind it to the datagrid? If so, then you may just select those fields in the query. Something like
cmd.CommandText = "SELECT ProductID, ProductName FROM Products Where CategoryID= " & cboCategory.SelectedValue
Regards,
Ankit Bhansali
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.