473,387 Members | 1,812 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,387 software developers and data experts.

How to Get DataSet ot DataTable from DataGrid

Hi
Every body
I m not able to get dataset or datatable from datagrid.
Now I m trying this code but this is always returns nothing.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim tbl As New DataTable
Dim ds As New DataSet
Dim dr As DataRow

tbl.Columns.Add("Col1")
tbl.Columns.Add("Col2")
dr = tbl.NewRow

dr("Col1") = "Neeraj"
dr("Col2") = "Pankaj"

tbl.Rows.Add(dr)
ds.Tables.Add(tbl)

DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim ds As DataSet
ds = CType(DataGrid1.DataSource, DataSet)
DataGrid2.DataSource = ds
DataGrid2.DataBind()
End Sub

Command button1 working successfully but command button2 not working
I got ds = nothing when I execute command button2 code
Please help me.

Jul 7 '06 #1
3 8385
neeraj wrote:
Hi
Every body
I m not able to get dataset or datatable from datagrid.
Now I m trying this code but this is always returns nothing.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim tbl As New DataTable
Dim ds As New DataSet
Dim dr As DataRow

tbl.Columns.Add("Col1")
tbl.Columns.Add("Col2")
dr = tbl.NewRow

dr("Col1") = "Neeraj"
dr("Col2") = "Pankaj"

tbl.Rows.Add(dr)
ds.Tables.Add(tbl)

DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim ds As DataSet
ds = CType(DataGrid1.DataSource, DataSet)
DataGrid2.DataSource = ds
DataGrid2.DataBind()
End Sub

Command button1 working successfully but command button2 not working
I got ds = nothing when I execute command button2 code
Please help me.
Did you click button two after button one? Since the first button sets
DataGrid1's DataSource, the second button canot refer to it until after
the first button is clicked.

Check right after "ds = CType(DataGrid1.DataSource, DataSet)".

Also, the DataBind may be gratuitous. So far, i have found no need for
them in my project.

B.

Jul 7 '06 #2

Brian Tkatch wrote:
neeraj wrote:
Hi
Every body
I m not able to get dataset or datatable from datagrid.
Now I m trying this code but this is always returns nothing.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim tbl As New DataTable
Dim ds As New DataSet
Dim dr As DataRow

tbl.Columns.Add("Col1")
tbl.Columns.Add("Col2")
dr = tbl.NewRow

dr("Col1") = "Neeraj"
dr("Col2") = "Pankaj"

tbl.Rows.Add(dr)
ds.Tables.Add(tbl)

DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim ds As DataSet
ds = CType(DataGrid1.DataSource, DataSet)
DataGrid2.DataSource = ds
DataGrid2.DataBind()
End Sub

Command button1 working successfully but command button2 not working
I got ds = nothing when I execute command button2 code
Please help me.

Did you click button two after button one? Since the first button sets
DataGrid1's DataSource, the second button canot refer to it until after
the first button is clicked.

Check right after "ds = CType(DataGrid1.DataSource, DataSet)".

Also, the DataBind may be gratuitous. So far, i have found no need for
them in my project.

B.
Boyishly i Click button2 after button1 click , but button2 click not
get datasource from datagrid. and also Datagrid1.Datasource returns
nothing .

Jul 9 '06 #3

neeraj wrote:
Brian Tkatch wrote:
neeraj wrote:
Hi
Every body
I m not able to get dataset or datatable from datagrid.
Now I m trying this code but this is always returns nothing.
>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
>
Dim tbl As New DataTable
Dim ds As New DataSet
Dim dr As DataRow
>
tbl.Columns.Add("Col1")
tbl.Columns.Add("Col2")
dr = tbl.NewRow
>
dr("Col1") = "Neeraj"
dr("Col2") = "Pankaj"
>
tbl.Rows.Add(dr)
ds.Tables.Add(tbl)
>
DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub
>
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim ds As DataSet
ds = CType(DataGrid1.DataSource, DataSet)
DataGrid2.DataSource = ds
DataGrid2.DataBind()
End Sub
>
Command button1 working successfully but command button2 not working
I got ds = nothing when I execute command button2 code
Please help me.
Did you click button two after button one? Since the first button sets
DataGrid1's DataSource, the second button canot refer to it until after
the first button is clicked.

Check right after "ds = CType(DataGrid1.DataSource, DataSet)".

Also, the DataBind may be gratuitous. So far, i have found no need for
them in my project.

B.
Boyishly i Click button2 after button1 click , but button2 click not
get datasource from datagrid. and also Datagrid1.Datasource returns
nothing .
That is odd. It looks like somehow Datagrid1.Datasource is being reset.

Add a breakpoint to you code, and watch what DataGrid1.DataSource is
set to. The one line of code

DataGrid1.DataSource = ds

sets it, but maybe it gets reset before the end of the sub?

B.

Jul 10 '06 #4

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

Similar topics

4
by: Wes | last post by:
I want to use a DataGrid and manually populate the data in the table. Does anyone know how this is done?? I want to create all the Columns, and then just add rows as my Program runs. Is there...
0
by: a | last post by:
I've read and split a delimited text file into a dataset. It looks fine in a datagrid (5 columns and 5,000 rows), but I've been trying, without success, to then insert the resulting dataset called...
0
by: a | last post by:
I've read and split a delimited text file into a dataset. It looks fine in a datagrid (5 columns and 5,000 rows), but I've been trying, without success, to then insert the resulting dataset called...
0
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is...
2
by: John Holmes | last post by:
I have a web interface where the user types in ID's one at a time. After an ID is typed in, a button is clicked and the button click event has code that does a query and returns a data reader and...
3
by: Ben Becker | last post by:
I am trying to build a custom crosstab type of grid where I take some items in a data grid and based on the content of the current item compared to the previous item, determine if a new row in a...
0
by: Bob Davies | last post by:
Hi I have a webservice that retrieves data from a database, this is then returned to the calling client application built in windows forms within a dataset, however upon attempting to create...
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...
17
by: A_PK | last post by:
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...
12
by: Brian | last post by:
I want to create an In Memory dataset. not connected to any database.. but putting my own info in from code or a file.... What are the steps to do this? Where can I find some info on how to do...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.