L
Lloyd Sheen
I have several apps that use a roll your own approach, but I am embarking on
a project which will not allow that with the time constraints.
I have gened up a little app to try the databinding approach. Simply it is
a page to maintain the Territories table in Northwind (SQL Server).
I have two SqlDataAdaptors - one for the list of Territories
- on for the individual
Territories row (uses parameter to select)
I created the two datasets. So far so good. I can open the page bind to a
dropdownlist, and get the details into a set of textboxes for each field.
Now I also have a button which simply outputs the text of the update
command. It uses the
UpdateCommand.CommandText from the dataset.
How does databinding help with updates. All parameter values are nothing
when I click the button?
The code follows:
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.TerritoryList.Fill(Me.DSTerritoryList)
Me.DropDownList1.DataBind()
End If
End Sub
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged
Me.OneTerritory.SelectCommand.Parameters(0).Value =
DropDownList1.SelectedItem.Value
Me.OneTerritory.Fill(Me.DsOneTerritory1)
Page.DataBind()
End Sub
Private Sub btnUpdateCommand_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdateCommand.Click
Me.txtUpdateCommand.Text = Me.OneTerritory.UpdateCommand.CommandText
End Sub
End Class
a project which will not allow that with the time constraints.
I have gened up a little app to try the databinding approach. Simply it is
a page to maintain the Territories table in Northwind (SQL Server).
I have two SqlDataAdaptors - one for the list of Territories
- on for the individual
Territories row (uses parameter to select)
I created the two datasets. So far so good. I can open the page bind to a
dropdownlist, and get the details into a set of textboxes for each field.
Now I also have a button which simply outputs the text of the update
command. It uses the
UpdateCommand.CommandText from the dataset.
How does databinding help with updates. All parameter values are nothing
when I click the button?
The code follows:
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.TerritoryList.Fill(Me.DSTerritoryList)
Me.DropDownList1.DataBind()
End If
End Sub
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged
Me.OneTerritory.SelectCommand.Parameters(0).Value =
DropDownList1.SelectedItem.Value
Me.OneTerritory.Fill(Me.DsOneTerritory1)
Page.DataBind()
End Sub
Private Sub btnUpdateCommand_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdateCommand.Click
Me.txtUpdateCommand.Text = Me.OneTerritory.UpdateCommand.CommandText
End Sub
End Class