By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,257 Members | 2,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,257 IT Pros & Developers. It's quick & easy.

Don't Understand

P: n/a
I am working on a walkthrough that allows editing contents of a datagrid
that is displaying some fields from a table in the Northwind DB. The update
code thay have you enter is shown below. As noted in the code, I am confused
by the statement that DIM's the "r" variable using "dsCategories", not
"dsCategories1". The code works fine but I am trying to understand what is
going on here.

TIA

Wayne

=================== code ======================
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.UpdateCommand

Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()

Dim categoryName, categoryDescription As String

Dim tb As TextBox

tb = CType(e.Item.Cells(2).Controls(0), TextBox)

categoryName = tb.Text

tb = CType(e.Item.Cells(3).Controls(0), TextBox)

categoryDescription = tb.Text

Dim r As dsCategories.CategoriesRow <= What is
"dsCategories"? My solution shows "dsCategories1"?

r = DsCategories1.Categories.FindByCategoryID(key)

r.CategoryName = categoryName

r.Description = categoryDescription

SqlDataAdapter1.Update(DsCategories1)

DataGrid1.DataBind()

'Switch current row out of edit mode

DataGrid1.EditItemIndex = -1

DataGrid1.DataBind()

End Sub

================================================== ===================
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I'm making an assumtion here, that you're working with a strongly types
dataset. If you aren't then ignore this posting...

IF you have atypes dataset, then there are pre-defined type for the
following....
DsCategories (Which derives from DataSet)
DsCategories.CategoriesRow (Which Derived From DataRow, this is a type, the
"dot" does not define it as a property, but as a type that is defined within
the DsCategories class/namespace)
DsCategories1 is an instance of a Strongly Types Dataset, which is of the
type DsCategories

so r is being declared as a specific type of DataRow,
Dim r As dsCategories.CategoriesRow
then its being set to be equal to the row, within your instance of the
DsCategories dataset, categoryID is equal to some value
r = DsCategories1.Categories.FindByCategoryID(key)
if you changed your code so that the dataset variable was something more
generic like ds, instead of DsCategories1, then it might make a little more
sense.
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I am working on a walkthrough that allows editing contents of a datagrid
that is displaying some fields from a table in the Northwind DB. The update code thay have you enter is shown below. As noted in the code, I am confused by the statement that DIM's the "r" variable using "dsCategories", not
"dsCategories1". The code works fine but I am trying to understand what is
going on here.

TIA

Wayne

=================== code ======================
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.UpdateCommand

Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()

Dim categoryName, categoryDescription As String

Dim tb As TextBox

tb = CType(e.Item.Cells(2).Controls(0), TextBox)

categoryName = tb.Text

tb = CType(e.Item.Cells(3).Controls(0), TextBox)

categoryDescription = tb.Text

Dim r As dsCategories.CategoriesRow <= What is
"dsCategories"? My solution shows "dsCategories1"?

r = DsCategories1.Categories.FindByCategoryID(key)

r.CategoryName = categoryName

r.Description = categoryDescription

SqlDataAdapter1.Update(DsCategories1)

DataGrid1.DataBind()

'Switch current row out of edit mode

DataGrid1.EditItemIndex = -1

DataGrid1.DataBind()

End Sub

================================================== ===================

Nov 18 '05 #2

P: n/a
Thanks for the reply David. Let me try to digest your information.

Wayne

"David Jessee" <dj*****@houston.rr.com> wrote in message
news:eP****************@tk2msftngp13.phx.gbl...
I'm making an assumtion here, that you're working with a strongly types
dataset. If you aren't then ignore this posting...

IF you have atypes dataset, then there are pre-defined type for the
following....
DsCategories (Which derives from DataSet)
DsCategories.CategoriesRow (Which Derived From DataRow, this is a type, the "dot" does not define it as a property, but as a type that is defined within the DsCategories class/namespace)
DsCategories1 is an instance of a Strongly Types Dataset, which is of the
type DsCategories

so r is being declared as a specific type of DataRow,
Dim r As dsCategories.CategoriesRow
then its being set to be equal to the row, within your instance of the
DsCategories dataset, categoryID is equal to some value
r = DsCategories1.Categories.FindByCategoryID(key)
if you changed your code so that the dataset variable was something more
generic like ds, instead of DsCategories1, then it might make a little more sense.
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I am working on a walkthrough that allows editing contents of a datagrid
that is displaying some fields from a table in the Northwind DB. The

update
code thay have you enter is shown below. As noted in the code, I am

confused
by the statement that DIM's the "r" variable using "dsCategories", not
"dsCategories1". The code works fine but I am trying to understand what is going on here.

TIA

Wayne

=================== code ======================
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.UpdateCommand

Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()

Dim categoryName, categoryDescription As String

Dim tb As TextBox

tb = CType(e.Item.Cells(2).Controls(0), TextBox)

categoryName = tb.Text

tb = CType(e.Item.Cells(3).Controls(0), TextBox)

categoryDescription = tb.Text

Dim r As dsCategories.CategoriesRow <= What is
"dsCategories"? My solution shows "dsCategories1"?

r = DsCategories1.Categories.FindByCategoryID(key)

r.CategoryName = categoryName

r.Description = categoryDescription

SqlDataAdapter1.Update(DsCategories1)

DataGrid1.DataBind()

'Switch current row out of edit mode

DataGrid1.EditItemIndex = -1

DataGrid1.DataBind()

End Sub

================================================== ===================


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.