0
我想使用他/她的用戶id從Web服務器數據庫中將客戶信息從Microsoft SQL Server數據庫中刪除到Web表單上,我可以得到一些幫助。從sql server數據庫中刪除信息
我想使用他/她的用戶id從Web服務器數據庫中將客戶信息從Microsoft SQL Server數據庫中刪除到Web表單上,我可以得到一些幫助。從sql server數據庫中刪除信息
你可以通過編寫一個類將定義一個客戶是什麼開始:
Public Class Customer
Public Property Id As Integer
Public Property FirstName As String
Public Property LastName As String
End Class
然後一個方法來從數據庫中檢索該客戶:
Public Function GetCustomer(ByVal CustomerId As Integer) As Customer
Using conn = New SqlConnection("Data Source=serverName;Initial Catalog=databaseName;User Id=username;Password=password;")
Using cmd = conn.CreateCommand()
conn.Open()
cmd.CommandText = "SELECT id, first_name, last_name FROM customers WHERE id = @id"
cmd.Parameters.AddWithValue("@id", CustomerId)
Using reader = cmd.ExecuteReader()
While reader.Read()
Dim Customer = New Customer()
Customer.Id = reader.GetInt32(reader.GetOrdinal("id"))
Customer.FirstName = reader.GetInt32(reader.GetOrdinal("first_name"))
Customer.LastName = reader.GetInt32(reader.GetOrdinal("last_name"))
Return Customer
End While
End Using
End Using
End Using
Return Nothing
End Function
,最後調用這個函數您的網頁表單:
Dim Customer = GetCustomer(123)
FirstNameTextBox.Text = Customer.FirstName
...
如果您想避免在喲中編寫SQL查詢你的代碼你可以使用ORM,如Entity Framework。
SQL的標籤?你已經做了什麼?你卡在哪裏? 更多詳細plz – SwissGuy 2011-05-09 08:43:37