473,729 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.DataSo urce.

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.DataS ource

Dim mydataview As New
DataView(mydata set1.Tables(Glo bal.strTblName) )
Dim strInput

strInput = InputBox("test" )
mydataview.RowF ilter = "Custno = " & strInput & ""

DataGrid1.Datas ource= mydataview
' DataGrid1.DataS ource = mydataset1
' DataGrid1.DataM ember = GlobalDBExplore r.strTblName

Catch err As InvalidCastExce ption
MsgBox(err.Mess age)
Catch err As Exception

MsgBox(err.Mess age)
End Try
Nov 21 '05 #1
17 2766
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...depe nd on user's choice...

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

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.DataSo urce,
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******** ******@tk2msftn gp13.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.Def aultView;

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.Datas ource= 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.r owfilter = "xx = " & y & "'"
///

Than you can use one time

\\\
Datagrid1.datas ource = 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.r owfilter = "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.dataso urce.....
after i set the mydataset1 = datagrid.dataso urce, then i type the one u
mentioned, and bind it accordinly what u had mentioned....bu t i still
getting the error "sepcialize d cast error"......

because i bind the dataset based on datagrid.datasr ouce.....

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.dataso urce......

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******** ******@tk2msftn gp13.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.r owfilter = "xx = " & y & "'"
///

Than you can use one time

\\\
Datagrid1.datas ource = 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******** ********@TK2MSF TNGP15.phx.gbl. ..
hi cor, arun...

another problem.....

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

Cor, you mentioned
dataset.table(x ).defaultview.r owfilter = "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.dataso urce.....
after i set the mydataset1 = datagrid.dataso urce, then i type the one u
mentioned, and bind it accordinly what u had mentioned....bu t i still
getting the error "sepcialize d cast error"......

because i bind the dataset based on datagrid.datasr ouce.....

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.dataso urce......

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******** ******@tk2msftn gp13.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.r owfilter = "xx = " & y & "'"
///

Than you can use one time

\\\
Datagrid1.datas ource = 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(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) 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(d t)
DataGrid1.DataS ource = ds.Tables("APK" ).DefaultView
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
If ds.Tables("APK" ).DefaultView.R owFilter = "A = '2'" Then
ds.Tables("APK" ).DefaultView.R owFilter = ""
Else
ds.Tables("APK" ).DefaultView.R owFilter = "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.DataS ource =
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.datas ource. then i will get the specialied cast error...cos my
Datagrid.dataso urce 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 (GlobalDBExplor er.strTblName). DefaultView.Row Filter
= "ColumnName = ' & strInput & '"

DataGrid1.DataS ource =
dsFilter.Tables (GlobalDBExplor er.strTblName). DefaultView
Catch err As InvalidCastExce ption
MsgBox(err.Mess age)
Catch err As Exception

MsgBox(err.Mess age)

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.dataso urce ?

mydataset.Table s(TableName) = DataGrid.Dataso urce ?

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.Dataso urce
Since I am binding to a View, i can no longer get the datasource from
datagrid1 by just typing mydataset = datagrid.dataso urce....

pls guide
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:Og******** ******@TK2MSFTN GP12.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(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) 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(d t)
DataGrid1.DataS ource = ds.Tables("APK" ).DefaultView
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
If ds.Tables("APK" ).DefaultView.R owFilter = "A = '2'" Then
ds.Tables("APK" ).DefaultView.R owFilter = ""
Else
ds.Tables("APK" ).DefaultView.R owFilter = "A = '2'"
End If
End Sub
///

I hope this helps,

Cor

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

Private Sub WriteXML()
Dim mydataset As New DataSet
mydataset = DataGrid1.DataS ource
mydataset.Write Xml(Application .StartupPath & "\Demo.xml" )

End Sub

I can simply use mydataset = DataGrid.Dataso urce, 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******** ******@TK2MSFTN GP12.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(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) 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(d t)
DataGrid1.DataS ource = ds.Tables("APK" ).DefaultView
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
If ds.Tables("APK" ).DefaultView.R owFilter = "A = '2'" Then
ds.Tables("APK" ).DefaultView.R owFilter = ""
Else
ds.Tables("APK" ).DefaultView.R owFilter = "A = '2'"
End If
End Sub
///

I hope this helps,

Cor

Nov 21 '05 #10

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

Similar topics

2
945
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 datagrid. HTML Datagrid1 TemplateColumn Table Header information Detail Information
1
1389
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 generated by the wizards. I click my Orders button, grid displays as expected. I click my drop down box to filter out some specific records, every thing works as expected.
2
3309
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 the selected lie item at which case I would pop up a separate dialog box to do so, in the debugging code, the dataview.count would return 0. I get a error message because I tried to get values out of a dataview that holds 0 items. Does anyone...
3
2100
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 databases, the data is ordered alphabetically but is grouped by database. Here is an example of what is happening to the data in the datgrid with the code that I have now. DB1 Apple DB1 Bird DB1 Cake
5
2790
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 to the database to get the next page. Is there a way to use the dataset to allow us to read back and forth in it instead of going back to the database to get it? Thanks,
3
7111
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
3761
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 corresponding to permissions to certain data classes. I want to put the permission values in combo boxes in the grid and instead of displaying the numeric values, have the combo box display a string that corresponds to the numeric value (i.e. No...
3
2520
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 others. One of the custom format is as follows: dsmessages_dt.Columns.Add("Image", GetType(Image)) I had a problem of when I used a checkbox in the grid that was bound to the datatable that it would not update my dataset. So I created another...
4
1205
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 used that DataSet as the DataSource for a DataGrid. I put a "fill" in my open form event.
0
8913
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.