PlayKid Posted August 19, 2005 Posted August 19, 2005 Hi all, I am try to make something that can update my database from my combobox, since I have 10 comboboxes on my form, and each perform the same function and had the same data source. The scenario is that: 1. I have 2 tables that needed to update 2. I need to check whether the string that I typed on my combo box is existed on my database, if not, then add to the database. The problems come in when I am trying to check my combo box, I tried many method, and still not working. Can someone lead me with this? Thanks very much PlayKid Private Sub SupplierActivitesInformation() Dim drSupplierActivities As DataRow Dim c As Control Dim count, countdata As Integer dtSupplierActivities = DsSupplierActivities1.Tables("SuppliersActivities") For count = 1 To 10 For Each c In ProvideActivitiesGroup.Controls If (c.Name = "ComboBox" & CStr(count)) And (c.Text <> "") Then drSupplierActivities = dtSupplierActivities.NewRow drSupplierActivities("SupplierNo") = SupplierNo + 1 ------------------------PROBLEM HERE----------------------------------- dtSupplierActivities.Rows.Add(drSupplierActivities) Call Savechanges(DsSupplierActivities1, daSupplierActivities) End If Next Next count End Sub Quote
HJB417 Posted August 20, 2005 Posted August 20, 2005 You might want to use custom attributes and mark your comboboxes with an attribute so it can be retrieved at runtime. Quote
PlayKid Posted August 20, 2005 Author Posted August 20, 2005 How do I do that? Not really understand your meaning..... Quote
Joe Mamma Posted August 20, 2005 Posted August 20, 2005 question. . . You want the user to be able to add activities to your database??? so lets say you had in the activity table: -------------- Walking Running -------------- The you want the the combo box to look something like this when dropped down: [____________]V |_____Walking_| |_____Running_| Now, lets say your user "fat-fingers" the combo box and enters: [_____Valking]V |_____Walking_| |_____Running_| and submits, Do you really want the database to reflect - -------------- Walking Running Valking -------------- ?????? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
PlayKid Posted August 20, 2005 Author Posted August 20, 2005 Joe: That's part of my idea, but since I have 10 combo boxes that do the same tricks, if I entered something on my box, then all other boxes do the same thing, which overwrites my text that I have entered on my combo box. I have changed my code, here is my updated code, but still gives me unwanted results. The results came back to me is, the item was added to the combo boxes successfully, but in my database, it repeated the item 10 times. it's really killing me, been trying figure out the codes for a week already.... Private Sub ActivitiesInformation(ByVal pActivityName As String) Dim drActivities As DataRow dtActivities = dsActivities1.Tables("Activities") drActivities = dtActivities.NewRow If dtActivities Is Nothing Then ActivityNo = 1 Else ActivityNo = dtActivities.Rows.Count End If drActivities("ActivitiyNo") = ActivityNo + 1 drActivities("ActivityProvided") = pActivityName dtActivities.Rows.Add(drActivities) End Sub Private Sub Combo(ByRef pCombo As ComboBox, ByVal dt As DataTable) Dim dr As DataRow If pCombo.Text <> "" Then dr = dt.NewRow dr("SupplierNo") = SupplierNo + 1 If CheckExistanceInComboBox(pCombo) = False Then Call ActivitiesInformation(pCombo.Text) dr("ActivityNo") = ActivityNo + 1 ElseIf CheckExistanceInComboBox(pCombo) = True Then dr("ActivityNo") = pCombo.ValueMember End If dtSupplierActivities.Rows.Add(dr) End If End Sub Private Sub SupplierActivitesInformation() Dim drSupplierActivities As DataRow dtSupplierActivities = DsSupplierActivities1.Tables("SuppliersActivities") Call Combo(ComboBox1, dtSupplierActivities) Call Combo(ComboBox2, dtSupplierActivities) Call Combo(ComboBox3, dtSupplierActivities) Call Combo(ComboBox4, dtSupplierActivities) Call Combo(ComboBox5, dtSupplierActivities) Call Combo(ComboBox6, dtSupplierActivities) Call Combo(ComboBox7, dtSupplierActivities) Call Combo(ComboBox8, dtSupplierActivities) Call Combo(ComboBox9, dtSupplierActivities) Call Combo(ComboBox10, dtSupplierActivities) Call Savechanges(dsActivities1, daActivities) Call Savechanges(DsSupplierActivities1, daSupplierActivities) End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.