473,287 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

DataGrid Bind to DataSet, then Bind to DaTaview, GOT ERROR...PLS HELP

I have problem databinding the DataGrid with DataView/DataSet after the
filter...
I create the following proceudre in order for user to filter as many as they
want, but the following code is only allow user to filter the first time,
when they tried the second time, the speficied cast error message will
prompt one....

I create a mydataset1 first, and the mydataset1 data source was getting from
DataGrid.DataSource.

then I create a DataView in order for me to filter....
after I enter the criteria, then will filter successfully the first time,
but not second time.

the I bind the DataGrid to DataView together......

The first filter is always successfully, I just can not filter the same data
second time...
I suspect it the DataView and DataSet problem, because at first I bind
datagrid1 and get the data source of datagrid1 form Dataset, but at the end
I bing the Datagird to the Dataview also.....so there are some error....i
think....

I just have no idea how to bind the Datagrid with Dataview, and allow user
to filter as many time as they want.....
could someone pls guide me.... here are the CODE
Try
Dim mydataset1 As New DataSet
mydataset1 = DataGrid1.DataSource

Dim mydataview As New
DataView(mydataset1.Tables(Global.strTblName))
Dim strInput

strInput = InputBox("test")
mydataview.RowFilter = "Custno = " & strInput & ""

DataGrid1.Datasource= mydataview
' DataGrid1.DataSource = mydataset1
' DataGrid1.DataMember = GlobalDBExplorer.strTblName

Catch err As InvalidCastException
MsgBox(err.Message)
Catch err As Exception

MsgBox(err.Message)
End Try
Nov 21 '05 #1
17 2714
APK,

You only have to bind the dataview one time to your datagrid.
There cannot be more datasources.

I have the idea that you are creating everytime a new dataview and try to
bind that new one against your datagrid.

I hope this helps,

Cor
Nov 21 '05 #2
Hi Cor,

my first problem is that....I dun have a fix dataset for me to bind to
datagrid1....
It is dynamically bind to datasetA or datasetB...depend on user's choice...

so I have to create anotehr local dataset1 and set to
mydataset1 = datagrid.datasource

after i get the mydataset1, then I create Dataview....
and user allow to do filter on dataview, then after the filtering, then
datagrid1 bind to dataview.....

please note that...I am using DataGrid = myDataView....
so for other feacture, i can not get the myDataSet1 = DataGrid.DataSource,
because i can not simply quote Dateset1 = DataView..

so I wish to know how the DataView can update the Dataset1.....

if I were to allow to create only one time dataview, may I know where should
I create the DataView ?


"Cor Ligthert" <no************@planet.nl> wrote in message
news:e5**************@tk2msftngp13.phx.gbl...
APK,

You only have to bind the dataview one time to your datagrid.
There cannot be more datasources.

I have the idea that you are creating everytime a new dataview and try to
bind that new one against your datagrid.

I hope this helps,

Cor

Nov 21 '05 #3
Hi,
Do it like this,

dim myDataView = myDataTable.DefaultView;

If you take DefaultView from a table and filter it with your criteria,
when you change a values in the dataview the change will pass through
to the underlying datatable as well.
So no need to bind it once again you may comment this

DataGrid1.Datasource= mydataview

Hope this helps,
Cheers,
Arun.
www.innasite.com

Nov 21 '05 #4
APK,

You can use as much dataviews as you want, however a datagrid can only one
use one datasource.

Probably the best choise for you ia uainf the defaultview what is in every
datatable which is a dataview.

Someting as setting it every time when the user have changed.

\\\
dataset.table(x).defaultview.rowfilter = "xx = " & y & "'"
///

Than you can use one time

\\\
Datagrid1.datasource = dataset.table(x).defaultview
///

I hope this helps,

Cor
Nov 21 '05 #5
hi cor, arun...

another problem.....

how could I bind the data to myDataview or myDataset ?...

Cor, you mentioned
dataset.table(x).defaultview.rowfilter = "xx = " & y & "'"

my problem is......my dataset is nothing at the very first beginning...
I have to based on datagrid data then only can decide my dataset1...

that is the reason that I set mydataset1 = datagrid.datasource.....
after i set the mydataset1 = datagrid.datasource, then i type the one u
mentioned, and bind it accordinly what u had mentioned....but i still
getting the error "sepcialized cast error"......

because i bind the dataset based on datagrid.datasrouce.....

I just wonder if I bind it wrongly ? or anyway way to solve that problem ?
my dataset is nothing at the beginning, I get the dataset data based on
datagird data.
mydataset = Datagrid.datasource......

after getting mydataset, then I using defauly view to bind to datagrid......

but I am still getting error when i did it repeatly....

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oa**************@tk2msftngp13.phx.gbl...
APK,

You can use as much dataviews as you want, however a datagrid can only one
use one datasource.

Probably the best choise for you ia uainf the defaultview what is in every
datatable which is a dataview.

Someting as setting it every time when the user have changed.

\\\
dataset.table(x).defaultview.rowfilter = "xx = " & y & "'"
///

Than you can use one time

\\\
Datagrid1.datasource = dataset.table(x).defaultview
///

I hope this helps,

Cor

Nov 21 '05 #6
To simply what I want to do....

I create a Dataset with a lot of infomration, then i create Dataview to
filter out all unwanted info....so that all the info in the Dataview is all
the information that I want ......

now I want to update the dataview to a dataset...cos I might perform other
update or delete command to update dataset........

pls guide me how to update DataView to Dataset ?

1- Dataset with All Info
2- create Dataview and filter out all unwanted info
3- update back Dataview to previous Dataset...

how to do that ?
so perhaps, my dataset have 1000 records, but after I did the filter, only
50 records i want...
so i update 50 back to dataset, and delete other 950 records....

hope someone to guide me...thank you....

" A_PK" <pk***@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
hi cor, arun...

another problem.....

how could I bind the data to myDataview or myDataset ?...

Cor, you mentioned
dataset.table(x).defaultview.rowfilter = "xx = " & y & "'"

my problem is......my dataset is nothing at the very first beginning...
I have to based on datagrid data then only can decide my dataset1...

that is the reason that I set mydataset1 = datagrid.datasource.....
after i set the mydataset1 = datagrid.datasource, then i type the one u
mentioned, and bind it accordinly what u had mentioned....but i still
getting the error "sepcialized cast error"......

because i bind the dataset based on datagrid.datasrouce.....

I just wonder if I bind it wrongly ? or anyway way to solve that problem ?
my dataset is nothing at the beginning, I get the dataset data based on
datagird data.
mydataset = Datagrid.datasource......

after getting mydataset, then I using defauly view to bind to
datagrid......

but I am still getting error when i did it repeatly....

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oa**************@tk2msftngp13.phx.gbl...
APK,

You can use as much dataviews as you want, however a datagrid can only
one use one datasource.

Probably the best choise for you ia uainf the defaultview what is in
every datatable which is a dataview.

Someting as setting it every time when the user have changed.

\\\
dataset.table(x).defaultview.rowfilter = "xx = " & y & "'"
///

Than you can use one time

\\\
Datagrid1.datasource = dataset.table(x).defaultview
///

I hope this helps,

Cor


Nov 21 '05 #7
APK,

I made a little sample for you.

\\\Needs a datagrid and a button on a form
Private ds As New DataSet
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("APK")
dt.Columns.Add("A")
dt.LoadDataRow(New Object() {"1"}, True)
dt.LoadDataRow(New Object() {"2"}, True)
dt.LoadDataRow(New Object() {"3"}, True)
ds.Tables.Add(dt)
DataGrid1.DataSource = ds.Tables("APK").DefaultView
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If ds.Tables("APK").DefaultView.RowFilter = "A = '2'" Then
ds.Tables("APK").DefaultView.RowFilter = ""
Else
ds.Tables("APK").DefaultView.RowFilter = "A = '2'"
End If
End Sub
///

I hope this helps,

Cor
Nov 21 '05 #8
Hi Cor, i understand what u mean....

but after I have done the filter, and set the DataGrid1.DataSource =
ds.Tables("APK").DefaultView
....I can perform filter feature actually. just that when I do know how to
retierve the filtered datasource and bind them to a new dataset to perform
other feature....

When I click other buttton, not the button u mentioned.....I need to know
what dataset is binding that datagrid. so in other button, i type myDataset
= Datagrid1.datasource. then i will get the specialied cast error...cos my
Datagrid.datasource is binding to a dataview, not dataset.... after I filter
all infomration liao, i have problem binding those information to other
dataset1...

u tried the following sure got problem

Declare a global dataset as dsFilter....

Try
Dim strInput
strInput = InputBox("test")

dsFilter.Tables(GlobalDBExplorer.strTblName).Defau ltView.RowFilter
= "ColumnName = ' & strInput & '"

DataGrid1.DataSource =
dsFilter.Tables(GlobalDBExplorer.strTblName).Defau ltView
Catch err As InvalidCastException
MsgBox(err.Message)
Catch err As Exception

MsgBox(err.Message)

End Try

I have no problem up to here.....but I want to
get the Datasource from DataGrid, then I will have problem

can i do anything like
mydataset = Datagird.datasource ?

mydataset.Tables(TableName) = DataGrid.Datasource ?

I need to get the Datasource from DataGrid from my other features....
I just no idea how to do that .....

but I have no problem if it is dataset.....
I can simply type mydataset = DataGrid.Datasource
Since I am binding to a View, i can no longer get the datasource from
datagrid1 by just typing mydataset = datagrid.datasource....

pls guide
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Og**************@TK2MSFTNGP12.phx.gbl...
APK,

I made a little sample for you.

\\\Needs a datagrid and a button on a form
Private ds As New DataSet
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("APK")
dt.Columns.Add("A")
dt.LoadDataRow(New Object() {"1"}, True)
dt.LoadDataRow(New Object() {"2"}, True)
dt.LoadDataRow(New Object() {"3"}, True)
ds.Tables.Add(dt)
DataGrid1.DataSource = ds.Tables("APK").DefaultView
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If ds.Tables("APK").DefaultView.RowFilter = "A = '2'" Then
ds.Tables("APK").DefaultView.RowFilter = ""
Else
ds.Tables("APK").DefaultView.RowFilter = "A = '2'"
End If
End Sub
///

I hope this helps,

Cor

Nov 21 '05 #9
i still have a sub Call WriteXML...using the filtered data to write to XML

Private Sub WriteXML()
Dim mydataset As New DataSet
mydataset = DataGrid1.DataSource
mydataset.WriteXml(Application.StartupPath & "\Demo.xml")

End Sub

I can simply use mydataset = DataGrid.Datasource, and get the reference, and
export as XML file.
but after I set to defauly view or use dataview, i can no longer the the
datasource references.

I just wonder how should I get the above mydataset bind to the filtered
datagrid datasource.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Og**************@TK2MSFTNGP12.phx.gbl...
APK,

I made a little sample for you.

\\\Needs a datagrid and a button on a form
Private ds As New DataSet
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("APK")
dt.Columns.Add("A")
dt.LoadDataRow(New Object() {"1"}, True)
dt.LoadDataRow(New Object() {"2"}, True)
dt.LoadDataRow(New Object() {"3"}, True)
ds.Tables.Add(dt)
DataGrid1.DataSource = ds.Tables("APK").DefaultView
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If ds.Tables("APK").DefaultView.RowFilter = "A = '2'" Then
ds.Tables("APK").DefaultView.RowFilter = ""
Else
ds.Tables("APK").DefaultView.RowFilter = "A = '2'"
End If
End Sub
///

I hope this helps,

Cor

Nov 21 '05 #10
APK,

When you want to set another datasource to a datagrid than you first have to
do.

datagrid.datasource = nothing

I hope this helps,

Cor
Nov 21 '05 #11
APK

This is a complet new question and reading in the ADONET newsgroup I now
understand what you are after and have even for that a sample. However I
think that it becomes to much confusing for people who reads those threads
in future when the questions are placed in more newsgroups and they don't
see the relation between question and answers, so I stop with answering in
this thread.

Cor
Nov 21 '05 #12
I apologize for doing that....

It is because that after I post my query, then I only realized that there is
still one adonet newgroup which might be related to my topic, so I post my
question to that newsgroup...

I dun mean do that that....

If you do know the solution, pls kindly let me know.

THank you very much
"Cor Ligthert" <no************@planet.nl> wrote in message
news:uO****************@TK2MSFTNGP10.phx.gbl...
APK

This is a complet new question and reading in the ADONET newsgroup I now
understand what you are after and have even for that a sample. However I
think that it becomes to much confusing for people who reads those threads
in future when the questions are placed in more newsgroups and they don't
see the relation between question and answers, so I stop with answering in
this thread.

Cor

Nov 21 '05 #13
Hi APK,

Here is a sample code snippet, Thanks Cor for the code and I have
changed a little to work for your requirement,

Try this code.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Dim dt As New DataTable("APK")
dt.Columns.Add("A")
dt.LoadDataRow(New Object() {"1"}, True)
dt.LoadDataRow(New Object() {"2"}, True)
dt.LoadDataRow(New Object() {"3"}, True)
ds.Tables.Add(dt)
DataGrid1.DataSource = dt
Catch err As InvalidCastException
MsgBox(err.Message)
Catch err As Exception
MsgBox(err.Message)
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ds1 As New DataSet
Dim dp As New DataTable
Dim i As Int32
dp = ds.Tables("APK").Clone
Dim dt() As DataRow = ds.Tables("APK").Select("A = '2'")
'Use ImportRow method to copy from Products table to its clone.
For i = 0 To dt.Length - 1
dp.ImportRow(dt(i))
Next
ds1.Tables.Add(dp)
DataGrid1.DataSource = dp
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim i As Int32
Dim dt1 As New DataTable
dt1 = CType(DataGrid1.DataSource, DataTable)
dt1.DataSet.WriteXml("\Demo.xml")
End Sub

Hope this helps,

Cheers,
Arun.
www.innasite.com

Nov 21 '05 #14
Arun,

I readed in the ADONET newsgroup that this is probably what APX is needed.

However as you did, is this kind of answering confusing on questions in more
newsgroups.

(Changed a lot in this message so watch typos)

\\\
Dim dsNew as new dataset
Dim dv As New DataView(OriginalDataset.Tables("whatever"))
dv.RowFilter = "A = '1"
Dim dtnew As DataTable = OriginalDataset.Tables("whatever").Clone
For Each dvr As DataRowView In dv
dtnew.ImportRow(dvr.Row)
Next
dt.Clear()
dsNew.Tables.Add(dtnew)
dsNew.WriteXML("C:\mydataset.xml")
///

:-)

Cor
Nov 21 '05 #15
Hi Arun,

thank for the code...

another question...just wonder if there is a way to bind the datagrid back
to dataset instead of dataview and datatable ?

because if I do filter, then have to bind my datagrid to datatable or
dataview,
if I dun do filter, then my datagrid will bind to dataset....

Without Filter....following is my WriteXML code

Dim mydataset As New DataSet
mydataset = DataGrid1.DataSource
mydataset.WriteXmlSchema(Application.StartupPath &
"\DBexplorer\Demo.xsd")
mydataset.WriteXml(Application.StartupPath &
"\DBexplorer\Demo.xml")

WithFilter...following is my WriteXML code....

Dim dt1 As New DataTable
dt1 = CType(DataGrid1.DataSource, DataTable)
dt1.DataSet.WriteXml(Application.StartupPath &
"\DBexplorer\\Demo.xml")
so if I have done filter, then the code gave u will be working,
if i have not done filter, then the code u gave me will not be wokring....
so they all get datagrid.datasource from different source. one from Dataset,
one from either Dataview and DataTable...

how could I make all consistent ?

"Arun" <ar***************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi APK,

Here is a sample code snippet, Thanks Cor for the code and I have
changed a little to work for your requirement,

Try this code.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Dim dt As New DataTable("APK")
dt.Columns.Add("A")
dt.LoadDataRow(New Object() {"1"}, True)
dt.LoadDataRow(New Object() {"2"}, True)
dt.LoadDataRow(New Object() {"3"}, True)
ds.Tables.Add(dt)
DataGrid1.DataSource = dt
Catch err As InvalidCastException
MsgBox(err.Message)
Catch err As Exception
MsgBox(err.Message)
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ds1 As New DataSet
Dim dp As New DataTable
Dim i As Int32
dp = ds.Tables("APK").Clone
Dim dt() As DataRow = ds.Tables("APK").Select("A = '2'")
'Use ImportRow method to copy from Products table to its clone.
For i = 0 To dt.Length - 1
dp.ImportRow(dt(i))
Next
ds1.Tables.Add(dp)
DataGrid1.DataSource = dp
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim i As Int32
Dim dt1 As New DataTable
dt1 = CType(DataGrid1.DataSource, DataTable)
dt1.DataSet.WriteXml("\Demo.xml")
End Sub

Hope this helps,

Cheers,
Arun.
www.innasite.com

Nov 21 '05 #16
APK,

With or without filter

Dim dt1 As New DataTable
dt1 = CType(DataGrid1.DataSource, DataTable)
dt1.DataSet.WriteXml (Application.StartupPath &
"\DBexplorer\\Demo.xml")

This should have to work, Have you tried it!!!

Cheers,
Arun.

Nov 21 '05 #17
Well,,, thank for Arun and Cor...

"Arun" <ar***************@gmail.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com...
APK,

With or without filter

Dim dt1 As New DataTable
dt1 = CType(DataGrid1.DataSource, DataTable)
dt1.DataSet.WriteXml (Application.StartupPath &
"\DBexplorer\\Demo.xml")

This should have to work, Have you tried it!!!

Cheers,
Arun.

Nov 21 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
1
by: Guy Noir | last post by:
I am having trouble wrapping my head around a datagrid and datasource. I have it working, sort-of, but I'm having trouble refreshing my views. Here's what I have: A dataAdapter and dataSet...
2
by: Alpha | last post by:
I have a window application. In one of the form, a datagrid has a dataview as its datasource. Initial filtering result would give the datavew 3 items. When I double click on the datagrid to edit...
3
by: crjunk | last post by:
I have 4 different databases that I'm having to pull data from in order to populate a datagrid. I am able to do this, but my problem is that because I'm pulling the data from 4 different...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
3
by: suresh | last post by:
frenz, i need to disable the add new record mode in datarid. i just want to modify the existing records in the grid...but i dont want to add new records..how do i do that? -suresh
6
by: Ron L | last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying to display in a datagrid. This datasource has 4 columns that I am interested in here, a text column and 3 value columns...
3
by: Datatable Dataset Datagrid help | last post by:
Hi I am somewhat confused, I am new at VB.net I use XML data, I have a datagrid, I created a datatable so that I can create a custom format like true is this graphic false is this graphic and...
4
by: Art | last post by:
Hi, Once again, I'm stuck. I want to view a table using a DataGrid. I'd like to fiter that view by criteria on various fields. So far, I've created a DataAdapter, generated a DataSet and...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.