Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL VB.NET Server
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:
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 5-Sep-12 5:07am
Edited 8-Sep-12 2:21am
v6
Comments
maddy_7869324 at 15-Feb-13 8:30am
   
Thnax a lot Your this question and solutions from all helped me a lot
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

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()
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

GetView appears to be a custom method. Try debugging the method to find out what exactly is expected by that method.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I tried out.
As per your suggestion I debug the code still not able to understand why system shows that error.
 
Please help me.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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-
 
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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 544
2 Maciej Los 325
3 DamithSL 223
4 Mathew Soji 195
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,712
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100