473,757 Members | 2,066 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
17 2769
APK,

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

datagrid.dataso urce = 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******** ********@TK2MSF TNGP10.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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) 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(d t)
DataGrid1.DataS ource = dt
Catch err As InvalidCastExce ption
MsgBox(err.Mess age)
Catch err As Exception
MsgBox(err.Mess age)
End Try
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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.DataS ource = dp
End Sub

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
Dim i As Int32
Dim dt1 As New DataTable
dt1 = CType(DataGrid1 .DataSource, DataTable)
dt1.DataSet.Wri teXml("\Demo.xm l")
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(Origin alDataset.Table s("whatever") )
dv.RowFilter = "A = '1"
Dim dtnew As DataTable = OriginalDataset .Tables("whatev er").Clone
For Each dvr As DataRowView In dv
dtnew.ImportRow (dvr.Row)
Next
dt.Clear()
dsNew.Tables.Ad d(dtnew)
dsNew.WriteXML( "C:\mydataset.x ml")
///

:-)

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....follo wing is my WriteXML code

Dim mydataset As New DataSet
mydataset = DataGrid1.DataS ource
mydataset.Write XmlSchema(Appli cation.StartupP ath &
"\DBexplorer\De mo.xsd")
mydataset.Write Xml(Application .StartupPath &
"\DBexplorer\De mo.xml")

WithFilter...fo llowing is my WriteXML code....

Dim dt1 As New DataTable
dt1 = CType(DataGrid1 .DataSource, DataTable)
dt1.DataSet.Wri teXml(Applicati on.StartupPath &
"\DBexplorer\\D emo.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.dataso urce 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.goo glegroups.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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) 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(d t)
DataGrid1.DataS ource = dt
Catch err As InvalidCastExce ption
MsgBox(err.Mess age)
Catch err As Exception
MsgBox(err.Mess age)
End Try
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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.DataS ource = dp
End Sub

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
Dim i As Int32
Dim dt1 As New DataTable
dt1 = CType(DataGrid1 .DataSource, DataTable)
dt1.DataSet.Wri teXml("\Demo.xm l")
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.Wri teXml (Application.St artupPath &
"\DBexplorer\\D emo.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******** *************@l 41g2000cwc.goog legroups.com...
APK,

With or without filter

Dim dt1 As New DataTable
dt1 = CType(DataGrid1 .DataSource, DataTable)
dt1.DataSet.Wri teXml (Application.St artupPath &
"\DBexplorer\\D emo.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
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
1392
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
3310
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
2101
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
2791
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
7114
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
3766
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
2521
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
1208
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
9487
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
10069
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
9904
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
9884
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,...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6556
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
5168
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...
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.