hi. I am trying to write a "simple"program to access and edit data from an access database. trying to get the data to display from a combobox selection to an unbound datagrid. when I run the program I get the error and the explanation "Not allowed to change the 'ConnectionString' property. The connection's current state is open."
below is the code I am using and on my form I have the datagrid "dgMaleLeague" and combobox "cbMaleName"
hope somebody knows of a simple solution I am very much a beginner.
Thanks
Public
Class MaleLeague Dim conMDB As New OleDb.OleDbConnection Dim cmdMDB As New OleDb.OleDbCommand Dim rdrMDB As OleDb.OleDbDataReader Private Sub MaleLeague_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadconMDB.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\tennis.mdb"cmdMDB.Connection = conMDB
cmdMDB.CommandText =
"SELECT * FROM Player WHERE(Gender = 'Male')"cmdMDB.CommandType = CommandType.Text
conMDB.Open()
rdrMDB = cmdMDB.ExecuteReader
While rdrMDB.ReadcbMaleName.Items.Add(rdrMDB(
"Surname")) End WhilecbMaleName.SelectedIndex = 0
rdrMDB.Close()
conMDB.Close()
End Sub Private Sub loadMaleLeague()
conMDB.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\tennis.mdb"cmdMDB.Connection = conMDB
cmdMDB.CommandText =
"MaleLeague"cmdMDB.CommandType = CommandType.StoredProcedure
cmdMDB.Parameters.Add(
"@MaleLeague", OleDb.OleDbType.Char)cmdMDB.Parameters.Item(
"@MaleLeague").Value = cbMaleName.TextrdrMDB = cmdMDB.ExecuteReader
Dim adapter As New OleDb.OleDbDataAdapteradapter.SelectCommand = cmdMDB
Dim table As New DataSetadapter.Fill(table)
dgMaleLeague.DataSource = table
table.Tables(0).TableName =
"MaleLeague"dgMaleLeague.DataMember =
"MaleLeague" With dgMaleLeague.Columns(0).Width = 100
.Columns(1).Width = 100
.Columns(2).Width = dgMaleLeague.Width - 204
End WithrdrMDB.Close()
conMDB.Close()
End Sub Private Sub cbMaleName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbMaleName.SelectedIndexChangedloadMaleLeague()
End SubEnd
Class
Replies
Know the answer? Post it — somebody with the same question will find it here.