cancel
Showing results for 
Search instead for 
Did you mean: 

Please Help me

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

Dear Ankit Bhansali,

Thanks a lot friend. But error occure as "Additional Information: Cast from type 'Data Row View' to Type String is not valid." pls help me to solve my problem.

Thanks and best regards,

ZNP

Message was edited by: Zin Nwe Phyo

Message was edited by: Zin Nwe Phyo

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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