0

3日間探しましたが、必要なものが見つかりません。さびしいですが、ホテルのITを管理する会社に勤めています。HOTELNAME、Street、Zip、Phone などの列を持つアクセス データベースがあります。

ホテル名がフォームのコンボボックスに入力されています。基本的に、ユーザーがドロップダウンからホテルを選択すると、位置情報や電話などの他の行 (選択したアイテムの行と一致する) からのすべての情報を取得して、いくつかの LABELS を入力する必要がありますが、見つからないようですラベルに必要なコード。

CODE: パブリッククラス ニューチケット

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Me.HotelsdbTableAdapter.Fill(Me.HotelsDataSet1.hotelsdb)

    Try
        Dim MyConnection As System.Data.OleDb.OleDbConnection
        Dim DtSet As System.Data.DataSet
        Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
        MyConnection = New System.Data.OleDb.OleDbConnection _
        ("provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\David_2\Desktop 2\Skosh\hotelDB.xlsx'; Extended Properties=Excel 12.0;")
        MyCommand = New System.Data.OleDb.OleDbDataAdapter _
            ("select * from [Sheet1$]", MyConnection)
        MyCommand.TableMappings.Add("Table", "TestTable")
        DtSet = New System.Data.DataSet
        MyCommand.Fill(DtSet)

        ' cmbHotels.Items.Add = Sheet1$.Range("A1").Text

        MyConnection.Close()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try



End Sub


Private Sub Newticket_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    FrmMain.Hide()

End Sub
Private Sub NewTicket_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
    FrmMain.Show()
    Me.Close()

End Sub

Private Sub lblHotel_Click(sender As System.Object, e As System.EventArgs) Handles lblHotel.Click

End Sub

Private Sub Label1_Click(sender As System.Object, e As System.EventArgs) Handles lblPoc.Click

End Sub

Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged

End Sub

Private Sub Label7_Click(sender As System.Object, e As System.EventArgs) Handles Label7.Click

End Sub

Private Sub BindingSource1_CurrentChanged(sender As System.Object, e As System.EventArgs)

End Sub
Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs)

End Sub

Private Sub cmbHotels_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbHotels.SelectedIndexChanged




End Sub

Private Function Sheets(p1 As String) As Object
    Throw New NotImplementedException
End Function

Private Function Rows() As Object
    Throw New NotImplementedException
End Function

Private Function Sheet1() As Object
    Throw New NotImplementedException
End Function

Private Sub DataGridView1_CellContentClick_1(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs)

End Sub

Private Sub BindingSource1_CurrentChanged_1(sender As System.Object, e As System.EventArgs) Handles BindingSource1.CurrentChanged

End Sub

Private Sub FillByHotelToolStripButton_Click(sender As System.Object, e As System.EventArgs)
    Try
        Me.HotelsdbTableAdapter.FillByHotel(Me.HotelsDataSet1.hotelsdb)
    Catch ex As System.Exception
        System.Windows.Forms.MessageBox.Show(ex.Message)
    End Try

End Sub

基本的にコンボボックスからホテルを選択します。右側のいくつかのラベルには、ホテル情報を入力する必要があります。ラベルをどうすればいいのかわからない。コンボボックスは機能しています。

どうもありがとうございました

4

1 に答える 1

1

基本的にはこのように..

Private Sub cmbHotels_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbHotels.SelectedIndexChanged
If cmbHotels.SelectedIndex = -1 then exit sub

Dim sHotel As String = cmbHotels.Text
Dim dr As DataRow

MyCommand = New System.Data.OleDb.OleDbDataAdapter _
        ("select * from [Sheet1$] where HotelName = '" & sHotel & "'" ,MyConnection) 

DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)

dr = DtSet.Rows(0)

'fill your label now
lblStreet.Text = dr.item("Stree") '----- or whatever
'etc

End Sub
于 2013-09-05T06:18:09.643 に答える