我想從一個SQL表填充一個網頁。從SQL填充表單域的更好方法?
這就是我現在所擁有的,雖然我不知道這是否是應該做的事情最好的辦法,請給我點建議:
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
然後我用GetPersonDetails()函數在我的後端填充表格。
像這樣:
Dim userDetails as new userDetails
userdetails = getPersonDetails()
txtAddress.text = userdetails.address1
etc....
但是,也有像在用戶DB 50場,這似乎是一個避免重複打字......請幫我找到一個更好的方式來做到這一點。
謝謝!