Can´t bind DataView to DataGrid

O

Ola Myrgart

Hi !

Have a problem with following.

Sub BindData()
Dim myConnection As SqlConnection
Dim myDataAdapter As SqlDataAdapter
Dim myDataSet As DataSet
Dim myDataTable As DataTable
Dim myDataView As DataView
Dim myRow As DataRowView

myConnection = New SqlConnection(
"server=localhost;uid=sa;pwd=help;database=annonser" )
myDataAdapter = New SqlDataAdapter( "Select * From kunder",
myConnection )
myDataSet = New DataSet()
myDataAdapter.Fill( myDataSet, "kunder" )
myDataView = myDataSet.Tables ("kunder" ).DefaultView
myDataView.RowFilter = ddlLan.SelectedItem.Value
myDataView.Sort = "Datum DESC"

dgSoksida.DataSource = myDataView
dgSoksida.DataBind()
End Sub

Exception Details: System.Data.EvaluateException: Cannot find column
[none].


What´s the problem.

Please help !

OM "Myggan"
 
R

Rajesh Patel

you did not write, which line you are getting an error.
first check how many columns you are getting in datatable and dataview.

Rajesh Patel
 
L

Lan Ong[MSFT]

you need to specify which column you want to filter to the selected value,
e.g.

myDataView.RowFilter = "[columnname]= '" + ddlLan.SelectedItem.Value +
"'"
myDataView.RowFilter = "type='None'" where type is my columnname
hope that help,
Lan

Rajesh Patel said:
you did not write, which line you are getting an error.
first check how many columns you are getting in datatable and dataview.

Rajesh Patel


Ola Myrgart said:
Hi !

Have a problem with following.

Sub BindData()
Dim myConnection As SqlConnection
Dim myDataAdapter As SqlDataAdapter
Dim myDataSet As DataSet
Dim myDataTable As DataTable
Dim myDataView As DataView
Dim myRow As DataRowView

myConnection = New SqlConnection(
"server=localhost;uid=sa;pwd=help;database=annonser" )
myDataAdapter = New SqlDataAdapter( "Select * From kunder",
myConnection )
myDataSet = New DataSet()
myDataAdapter.Fill( myDataSet, "kunder" )
myDataView = myDataSet.Tables ("kunder" ).DefaultView
myDataView.RowFilter = ddlLan.SelectedItem.Value
myDataView.Sort = "Datum DESC"

dgSoksida.DataSource = myDataView
dgSoksida.DataBind()
End Sub

Exception Details: System.Data.EvaluateException: Cannot find column
[none].


What´s the problem.

Please help !

OM "Myggan"
 
O

Ola Myrgart

Thank you !

Now it works as it´s supposed to. I´ve only one more question and that
is, can I combine two DDL:S in my dataview. Is it possible to combine it
in the same row
as the first one?

The first one is like this :

myDataView.RowFilter = "Ort = '" + ddlLan.SelectedItem.Text + "'"

Once again - thank you !

OM "Myggan"
 
O

Ola Myrgart

Hi again !

Another thing came to me trying to get a view not filtered by the DDL.
How do I reset the filtering in my dataview - that is - How can I
display all items without filtering when I select all in the DDL. (Code
samples much needed)

Any ideas ?

OM "Myggan"
 
L

Lan Ong[MSFT]

You can combine like,
dv.RowFilter = "type='" + DropDownList1.SelectedItem.Value + "'" + " and
price >=" + DropDownList2.SelectedItem.Value
 
L

Lan Ong[MSFT]

You need to call datagrid.databind method everytime you want to reset the
view.
 
O

Ola Myrgart

Hi again and thank you for your answers. I´ve tried it out and it works
halfway. I tried to combine 2 DDL:s like:

myDataView.RowFilter = " Ort = '" + ddlLan.SelectedItem.text + "'" + "
and Kategori = '" + ddlKategori.SelectedItem.text + "'"

It work but not as it should. I tied to reset one DDL by :

If ddlLan.SelectedItem.Value = "none" then
myDataView.RowFilter = ""
End If

and I also set the AutoPostBAck for the DDL to "True". So the reset
works well. It´s the combined filtering that won´t work. Either one
takes control i seems. Separatly they work just fine.

Here´s the whole Sub:


Sub BindData()
Dim myConnection As SqlConnection
Dim myDataAdapter As SqlDataAdapter
Dim myDataSet As DataSet
Dim myDataTable As DataTable
Dim myDataView As DataView
Dim myRow As DataRowView

myConnection = New SqlConnection(
"server=localhost;uid=sa;pwd=idioterna;database=annonser" )
myDataAdapter = New SqlDataAdapter( "Select * From kunder",
myConnection )
myDataSet = New DataSet()
myDataAdapter.Fill( myDataSet, "kunder" )
myDataView = myDataSet.Tables( "kunder" ).DefaultView
myDataView.RowFilter = " Ort = '" + ddlLan.SelectedItem.text
+ "'" + " and Kategori = '" + ddlKategori.SelectedItem.text + "'"
myDataView.Sort = "Datum DESC"

If ddlLan.SelectedItem.Value = "none" then
myDataView.RowFilter = ""
End If

dgSoksida.DataSource = myDataView
dgSoksida.DataBind()
End Sub


Any ideas ?

OM "Myggan"
 
O

Ola Myrgart

Hi !

Forget it I´ve got it right now. Sometimes you can´t see the obviuos.

OM "Myggan"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top