In vb2010 I am trying to create a small program, I have a textbox and a combobox.
The combobox items are dynamically loaded from an XML file. And has items that correspond with the Groupname column in the access database.
The msaccess database has 3 columns (excl id), groupname, realname, emailaddress.
When I select in the combobox an item, records who has the same name in the groupname column, should select all the email addresses (seperated by a ";") and put them into the textbox.
For example:
When selected Group1 in the combobox.
1: Group1, Rick, rick @ rick.com
2: Group2, David, david @ david.com
3: Group1, Louise, louise @ louise.com
In this case the emailaddresses of records 1 and 3 should be into the textbox:
rick @ rick.com; louise @ louise.com
At the moment I receive an error message, I have tried to google the message but haven't found a solution for it:
Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.DataRow'
I have the following code, which isn't working yet, I hope someone can help me with this?
Thanks for any help.
The combobox items are dynamically loaded from an XML file. And has items that correspond with the Groupname column in the access database.
The msaccess database has 3 columns (excl id), groupname, realname, emailaddress.
When I select in the combobox an item, records who has the same name in the groupname column, should select all the email addresses (seperated by a ";") and put them into the textbox.
For example:
When selected Group1 in the combobox.
1: Group1, Rick, rick @ rick.com
2: Group2, David, david @ david.com
3: Group1, Louise, louise @ louise.com
In this case the emailaddresses of records 1 and 3 should be into the textbox:
rick @ rick.com; louise @ louise.com
At the moment I receive an error message, I have tried to google the message but haven't found a solution for it:
Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.DataRow'
I have the following code, which isn't working yet, I hope someone can help me with this?
VB.NET:
Private Sub ToAddressesSelect()
Try
Dim cmd As OleDbCommand = New OleDbCommand("SELECT Groupname, Emailaddress FROM email WHERE Groupname = '" + ComboBox1.SelectedText + "'", con)
con.Open()
Dim dr As OleDbDataReader = cmd.ExecuteReader()
If dr.HasRows = True Then
For Each row As DataRow In dr
'While dr.Read()
TextEdit1.Text = dr("Emailaddress").ToString()
'End While
Next
Else
MessageBox.Show("No data found!")
End If
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub EmailSonglist_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
DevExpress.UserSkins.BonusSkins.Register()
DevExpress.UserSkins.OfficeSkins.Register()
Dim fileI As FileInfo = New FileInfo(Application.StartupPath + "\groups.xml")
If fileI.Exists Then
Dim doc As XDocument = XDocument.Load(Application.StartupPath + "\groups.xml")
ComboBox1.Items.Add("To...")
For Each element As XElement In doc.Descendants("Group")
ComboBox1.Items.Add(element.Value)
Next
ComboBox1.SelectedIndex = 0
Else
MessageBox.Show("There is no addressbook available, please create one.")
Process.Start(Application.StartupPath + "\Addressbook.exe")
End If
End Sub
Thanks for any help.