Click here to Skip to main content
15,125,121 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wont to fill datagridview when item is selected from listbox
i write code but it gives me this error
Operator '&' is not defined for string "SELECT DeptName FROM  Department" and type 'DataRowView'.
VB



What I have tried:

this my code
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        cmd = New OleDbCommand("SELECT DeptName FROM  Departments inner  JOIN Faculties ON Faculties.ID = Departments.FacID where FacID='" & ListBox1.SelectedValue & "'", conn)
        Dim daa As New OleDbDataAdapter(cmd)
        Dim dtt As New DataTable
        daa.Fill(dtt)
        dgv.DataSource = dtt
    End Sub
Posted
Comments
CHill60 10-Apr-17 10:32am
   
Use OleDbParameters instead of concatenated strings (which you should NEVER use) and your problem will go away
NebroProg 10-Apr-17 10:37am
   
ok
I will be try
thnk's ^_^
Richard MacCutchan 10-Apr-17 10:34am
   
The string shown in your code does not match the string shown in your error message. But in either case you should not use string concatenation for SQL commands, use proper parameterised queries.
NebroProg 11-Apr-17 0:50am
   
when I pass parameter this error occur Conversion from type 'DataRowView' to type 'String' is not valid
kumar nitesh 11-Apr-17 2:32am
   
As per the error statement it looks like you are trying to convert your datagridrow to string . can you please show me your html code ??
NebroProg 13-Apr-17 8:52am
   
I know its vulnerable to sql injection ,it's desktop application

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