I am trying to make saved data stay on the page after saving.
What's the best way? and what the correct syntax?
in my first example, I created a sub within my class then a private sub on the code behind page and a stored procedure that will pull the data back in according to employee ID but the data is not staying on the page when I click "Save".
Public Sub New(ByVal employeeId As Integer)
Dim conn As SqlConnection = Nothing
Dim cmd As SqlCommand = Nothing
Dim rd As SqlDataReader = Nothing
Try
Dim connStr As String
connStr = ConfigurationManager.ConnectionStrings("TestConnectionString").ConnectionString
conn = New SqlConnection("GetEmployeeData")
conn.Open()
rd = cmd.ExecuteReader()
With cmd
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@employee_id", SqlDbType.Int)
.Parameters("@employee_is").Value = employeeId
.Connection = conn
End With
conn.Open()
rd = cmd.ExecuteReader()
While (rd.Read())
_employee_id = employeeId
If IsDBNull(rd("personEmployee")) = True Then
_personEmployee = ""
Else
_personEmployee = "" & CType(rd("personEmployee"), String)
End If
_lastName = CType(rd("lastName"), String)
_firstName = CType(rd("firstName"), String)
If IsDBNull(rd("middleName")) = True Then
_middleName = ""
Else
_middleName = "" & CType(rd("middleName"), String)
End If
Private Sub FillPage(ByVal employeeId As Integer)
Try
Dim per As editpersonnel = New editpersonnel(employeeId)
txtPersonEmployee.Text = per.personEmployee
txtLastName.Text = per.lastName
txtFirstName.Text = per.firstName
txtMiddleName.Text = per.middleName
txtPrimaryEmail.Text = per.primaryEmail
txtTelephone.Text = per.telephone
txtExt.Text = per.ext
txtMobile.Text = per.mobile
txtPager.Text = per.pager
If txtActualStart.Text.Length > 0 Then
per.startDate = txtActualStart.Text
Else
per.startDate = Nothing
End If
In the second example, I created a stored procedure, and a sub to fill the page in the code behind but the data that appears on the page is what I have in code.
Private Sub PopulateFormFields()
Dim conn As SqlConnection = Nothing
Dim cmd As SqlCommand = Nothing
Dim rd As SqlDataReader = Nothing
Try
Dim connStr As String
connStr = ConfigurationManager.ConnectionStrings("TestConnectionString").ConnectionString
conn = New SqlConnection("IUpdateEmployee")
conn.Open()
rd = cmd.ExecuteReader()
lblRecordNumber.Text = employee_id.ToString()
If IsDBNull(rd("@personEmployee")) = True Then
End If
txtLastName.Text = ("@lastName")
txtFirstName.Text = ("@firstName")
txtMiddleName.Text = ("@middleName")
txtPrimaryEmail.Text = ("@primaryemail")
txtTelephone.Text = ("@telephone")
[Modified: just removed the extra pre tags that were throwing off the formatting]