Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to Fetch record from Sql & display it in Data Grid View against the selection of Combo Box value.I am using Vb.net & Sql Server '05.

I am using Following code:
VB
Public Function GetView(ByVal strQuery As String) As DataSet
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(strQuery, SetCon())
        da.Fill(ds, "New")
        Return ds
    End Function

Dim dsvalue As DataSet
        dsvalue = obj.GetView("Select p.PO_no,p.Date,s.Name from PO_Header p, SupplierMaster s Where p.Sup_no = " & cmbSupplierName.SelectedValue & ";" )
    DataGridView1.DataSource = dsvalue.Tables(0).DefaultView

System show me Error :Operator '&' is not defined for string "Select p.PO_no,p.Date,s.Sup_name" and type 'DataRowView'.
Posted
Updated 8-Sep-12 1:21am
v6
Comments
maddy_7869324 15-Feb-13 8:30am    
Thnax a lot Your this question and solutions from all helped me a lot

Dim connectionstring As String = "Driver=MySQL ODBC 3.51 Driver;Server=localhost;port=3306;uid=root;pwd=admin;Database=dbname;"
Dim conn As New OdbcConnection(connectionstring)
conn.Open()
Dim da As New OdbcDataAdapter("select * from Userpass where Username like '%" & ComboBox1.Text & "%'", conn)
Dim ds As New DataSet
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
conn.Close()
 
Share this answer
 
GetView appears to be a custom method. Try debugging the method to find out what exactly is expected by that method.
 
Share this answer
 
I tried out.
As per your suggestion I debug the code still not able to understand why system shows that error.

Please help me.
 
Share this answer
 
If your combobox is data bounded than try to run this code through another control event. I mean Insert a button into Form and run your code in click event of that button.Best way to do that-
1.Convert your combobox.selectedvalue into the data type of column data type in database. ( I assume it is integer type)

2.into the click event of button-

SQL
Dim supNo as integer=CInt(cmbSupplierName.SelectedValue)
Dim dsvalue As DataSet
        dsvalue = obj.GetView("Select p.PO_no,p.Date,s.Name from PO_Header p, SupplierMaster s Where p.Sup_no = " & supNo & ";" )
    DataGridView1.DataSource = dsvalue.Tables(0).DefaultView
 
Share this answer
 
Thank You for solution.

But I am facing problem in query .
System shows me message :Operator '&' is not defined for string "Select p.PO_no,p.Date,s.Sup_name" and type 'DataRowView'.

One more question: How to change data type of combobox.selected value in database.

Please Help
 
Share this answer
 
That error may be due to the SelectedValue data type is not defined.

so what type should the selectedvalue be in the script?

if it is a int then you won't have to add the ' ' before and after the value.

You have look at that string as if it where in sql and make that string being sent look the same to allow it to work.

Hope that helps.
 
Share this answer
 
v2
i think you have to write like this

dsvalue = obj.GetView("Select p.PO_no,p.Date,s.Name from PO_Header p, SupplierMaster s Where p.Sup_no = '" & cmbSupplierName.SelectedValue & "'" )

hope that helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900