Don't Understand

W

Wayne Wengert

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

=====================================================================
 
D

David Jessee

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top