我是新來的ASP.net編程,我有一個問題,關於如何傳遞從下拉列表中檢索到的數據,然後將其填充到標籤,以便它可以存儲在數據庫。這應該是來自某人的簡單回答,但我卡住了。我現在處於相當深的狀態,這就是完成我的表單所需的一切。這是下面的代碼;ASP VB - Dropdownlist數據標籤
Private Sub FillPersonList()
Dim strConn As String = ConfigurationManager.ConnectionStrings("SQL2K-ConnectionString").ConnectionString
Dim con As New SqlConnection(strConn)
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT Distinct(LName +', '+ FName) AS 'Name', PNumber FROM [SQL88K].ASD.dbo.Check WHERE insertdatetime BETWEEN getdate() - 7 AND getdate() And Room = @Room"
cmd.Parameters.AddWithValue("@Room", DDRoom.SelectedItem.Value)
Dim objDs As New DataSet()
Dim dAdapter As New SqlDataAdapter()
dAdapter.SelectCommand = cmd
con.Open()
dAdapter.Fill(objDs)
con.Close()
If objDs.Tables(0).Rows.Count > 0 Then
DDPerson.DataSource = objDs.Tables(0)
DDPerson.DataTextField = "PName"
DDPerson.DataValueField = "PName"
lblPNumber.Text = "PNumber" 'This is where i'm trying to populate the label!
DDPerson.DataBind()
DDPerson.Items.Insert(0, "<--Select Person-->")
End If
End Sub
把東西放在標籤中與將其存儲在數據庫中無關。你的問題是否有點亂碼? –