Hello!

I've an ASP web page in which a button click handler requires access to the page's member parameters. Every time the button routine runs however, the member parameters seem to be null (values = NOTHING).

The code is appended below. Sorry for the length of the code, but I wanted to make sure I wasn't missing anything, and that my problem was clear.

The page initializes fine, and the date is pulled correctly and displayed in the grid upon load... but whenever the button routine commences, dsEmployee is a null value (I checked with the debugger).

I've tried prefacing the variable names with ME, but this changed nothing.

Since I'm a newbie, I've a sneaking suspicion that the solution will be so obvious as to verge on the ridiculous... Any ideas?



VB Code:
  1. Imports System.Data.SqlClient
  2. Imports System.Data
  3.  
  4.  
  5. Partial Class AddEmployee
  6.     Inherits System.Web.UI.Page
  7.  
  8.     Dim daEmployee As SqlDataAdapter
  9.     Dim dsEmployee As DataSet
  10.  
  11.     Const stConnection As String = "Data Source=.\sqlexpress;Initial Catalog=dbBatteries;Integrated Security=True"
  12.  
  13.     Const stSelect As String = "SELECT LastName, FirstName, Number, EmployeeID " + _
  14.                                 "FROM tblEmployee ORDER BY LastName"
  15.  
  16.     Const stTableName As String = "Employee"
  17.  
  18.  
  19.  
  20.  
  21.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  22.  
  23.         If Not Me.IsPostBack Then
  24.  
  25.             ' data connection
  26.             daEmployee = New SqlDataAdapter(stSelect, stConnection)
  27.  
  28.             ' data island
  29.             dsEmployee = New DataSet(stTableName)
  30.  
  31.             ' fill data island
  32.             daEmployee.Fill(dsEmployee, stTableName)
  33.  
  34.             ' bind data to control
  35.             grdEmployee.DataSource = dsEmployee.Tables(stTableName)
  36.             grdEmployee.DataBind()
  37.  
  38.         End If
  39.  
  40.     End Sub
  41.  
  42.     Protected Sub butInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butInsert.Click
  43.  
  44.         'daEmployee.InsertCommand.CommandText = stInsert
  45.         Dim drEmployee As DataRow
  46.  
  47.         ' create a datarow object (there exists no constructor)
  48.         drEmployee = dsEmployee.Tables(stTableName).NewRow()
  49.  
  50.         ' fill in its values
  51.         drEmployee.Item("LastName") = txtLastName.Text
  52.         drEmployee.Item("FirstName") = txtFirstName.Text
  53.         drEmployee.Item("Number") = CInt(txtNumber.Text)
  54.  
  55.         ' add it to the data island
  56.         dsEmployee.Tables(stTableName).Rows.Add(drEmployee)
  57.  
  58.     End Sub
  59.  
  60. End Class