Dim sur As String = ListBox1.Items(ListBox1.SelectedIndex)
Подскажите где здесь проблема?
http://i8.fastpic.ru/big/2010/0808/3a/3 ... fb473a.jpg
http://depositfiles.com/files/fgwidleqr - здесь база данных
http://depositfiles.com/files/djtccs7og - здесь отрывок из книжки, откуда взято тех.задание.
- Код: Выделить всё
Imports System.Data.OleDb
Public Class Form1
Private Sub StudentsBindingNavigatorSaveItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles StudentsBindingNavigatorSaveItem.Click Me.Validate()
Me.StudentsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.ContractsDataSet)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: данная строка кода позволяет загрузить данные в таблицу "ContractsDataSet.Students".
'При необходимости она может быть перемещена или удалена.
Me.StudentsTableAdapter.Fill(Me.ContractsDataSet.Students)
End Sub
Public Sub Fill_ListBox()
Dim DS As New ContractsDataSet
Dim CN As New OleDb.OleDbConnection
CN.ConnectionString = "Provider=Microsoft.ACE.OleDb.12.0; " &
"Data Source=""E:\DISTR\VisualBasic2010\DataBases\Contracts.accdb"";User ID=Admin"
CN.Open()
If CN.State <> ConnectionState.Open Then MessageBox.Show("Not connected")
Dim quer As String = "SELECT Students.StudSurName FROM Students"
Dim com As New OleDb.OleDbCommand(quer, CN)
Dim read As OleDb.OleDbDataReader = com.ExecuteReader()
While read.Read()
ListBox1.Items.Add(read(0).ToString())
End While
CN.Close()
End Sub
Public Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ListBox1.SelectedIndexChanged
Dim DS As New ContractsDataSet
Dim CN As New OleDb.OleDbConnection
CN.ConnectionString = "Provider=Microsoft.ACE.OleDb.12.0; " &
"Data Source=""E:\DISTR\VisualBasic2010\DataBases\Contracts.accdb"";User ID=Admin"
CN.Open()
If CN.State <> ConnectionState.Open Then MessageBox.Show("Not connected")
' получение значения выбранного элемента в ListBox
Dim sur As String = ListBox1.Items(ListBox1.SelectedIndex)
Dim quer As String = "SELECT Payments.PaySum, Payments.PayDate FROM Students, " &
"Payments WHERE RefStudent = IDStudent And StudSurName = '" + sur + "'"
Dim com As New OleDb.OleDbCommand(quer, CN)
Dim read As OleDb.OleDbDataReader = com.ExecuteReader()
REM вспомогательная переменная
Dim s1(2) As [String]
REM предварительная очистка DataGridView
DataGridView1.Rows.Clear()
REM заполнение компонента DataGridView
While read.Read()
s1.SetValue(read(0).ToString(), 0)
s1.SetValue(read(1).ToString(), 1)
DataGridView1.Rows.Add(s1)
End While
CN.Close()
End Sub
End Class