Populate a form from SQL
- by xrum
Hi,
I am trying to populate a web from from a SQL table.
This is what I have right now, though I am not sure if it's the best way to do things, please give me suggestions:
Public Class userDetails
Public address1 As String
Public address2 As String
Public city As String
...
...
...
End Class
Public Class clsPerson
'set SQL connection
Dim objFormat As New clsFormat
Dim objConn As New clsConn()
Dim connStr As String = objConn.getConn()
Dim myConnection As New Data.SqlClient.SqlConnection(connStr)
Public Function GetPersonDetails() As userDetails
'connection and all other good stuff here
Try
' Execute the command
myConnection.Open()
dr = myCommand.ExecuteReader()
' Make sure a record was returned
If dr.Read() Then
' Create and Populate ApplicantDetails
userDetails.address1 = dr("address1")
userDetails.address2 = objFormat.CheckNull(dr("address2"))
userDetails.city = objFormat.CheckNull(dr("city"))
....
Else
Err.Raise(4938, "clsUser", "Error in GetUserDetails - User Not Found")
End If
dr.Close()
Finally
myConnection.Close()
End Try
Return userDetails
End Function
i then use GetPersonDetails() function in my backend to populate the form.
like so:
Dim userDetails as new userDetails
userdetails = getPersonDetails()
txtAddress.text = userdetails.address1
etc....
however, there are like 50 fields in the User db, and it seems like a lot of retyping... please help me find a better way to do this.
Thank you!