|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to Get DataSet ot DataTable from DataGridEvery 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. neeraj wrote:
Show quoteHide quote > Hi Did you click button two after button one? Since the first button sets> 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. 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. Brian Tkatch wrote:
Show quoteHide quote > neeraj wrote: Boyishly i Click button2 after button1 click , but button2 click not> > 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. get datasource from datagrid. and also Datagrid1.Datasource returns nothing . neeraj wrote:
Show quoteHide quote > Brian Tkatch wrote: That is odd. It looks like somehow Datagrid1.Datasource is being reset.> > 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 . 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.
Date Sort
Sharing Class Data With Multiple Forms Urgent! Get rowindex - datagrid navigation Need to capture all keystrokes to my application Difference between MyBase and Me Limit bandwith of my application VB Net 2005 and Email! combobox view display width question Images in a Windows DataGrid Working with BindingSource & AddNew |
|||||||||||||||||||||||