473,661 Members | 2,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

insert and update database table rows using textboxes

25 New Member
Hi there, I'm having a problem with updating and/or inserting rows in a table in my database. I have a form with a combobox, 10 textboxes, and save button. Here, the combobox if filled with illnesses from the diagnose table in my database. Diagnose table's structure is: f_id, illness, symptoms, so an illness can have many symptoms. If an item is selected from the combobox, the symptoms will be displayed on the textboxes. I already got this working. My problem is that I should make it able to insert or update the rows in the table. Here's my code for reading the illness and symptoms:
Expand|Select|Wrap|Line Numbers
  1. Call Connect()
  2.             Dim str As String
  3.             str = "Select sname from diagnose where first_aid = @ill"
  4.             cmd.Parameters.AddWithValue("ill", cmbRecord.Text)
  5.             cmd.Connection = myConn
  6.             cmd.CommandText = str
  7.             dtr = cmd.ExecuteReader
  8.  
  9.             Dim symptoms As New List(Of String)
  10.             While dtr.Read()
  11.                 symptoms.Add(dtr("sname"))
  12.             End While
  13.             'set available symptoms
  14.             Dim arrayOfTextboxes() As TextBox = {symp0, symp1, symp2, symp3, symp4, symp5, symp6, symp7, symp8, symp9}
  15.             Dim i As Integer = 0
  16.             For i = 0 To symptoms.Count - 1
  17.                 arrayOfTextboxes(i).Text = symptoms(i)
  18.             Next
  19.             'clear other textboxes
  20.             For j = i To UBound(arrayOfTextboxes)
  21.                 arrayOfTextboxes(j).Text = String.Empty
  22.             Next
  23.             myConn.Close()
  24.  
and here's my code for inserting or updating. I get error "Parameter 'ill' has already been defined."
Expand|Select|Wrap|Line Numbers
  1. Call Connect()
  2.             If Duplicate() = False Then
  3.                 Dim dt As New DataTable("diagnose")
  4.                 Dim row As DataRow
  5.                 Dim arrayOfTextboxes() As TextBox = {symp0, symp1, symp2, symp3, symp4, symp5, symp6, symp7, symp8, symp9}
  6.                 Dim symptoms As New List(Of String)
  7.                 STRSQL = "insert into diagnose values (@ill, @sym)"
  8.                 Using myCmd = New MySqlCommand(STRSQL, myConn)
  9.                     myConn.Open()
  10.  
  11.                     Dim i As Integer = 0
  12.                     For i = 0 To arrayOfTextboxes.Count - 1
  13.                         If String.IsNullOrEmpty(arrayOfTextboxes(i).Text) Then Continue For
  14.                         If arrayOfTextboxes(i).Text <> "" Then
  15.                             myCmd.Parameters.AddWithValue("ill", cmbRecord.Text)
  16.                             myCmd.Parameters.AddWithValue("sym", arrayOfTextboxes(i).Text)
  17.                             row = dt.NewRow()
  18.                             myCmd.ExecuteNonQuery()
  19.                         End If
  20.                     Next
  21.                     MsgBox("Record Added")
  22.                     myConn.Close()
  23.                 End Using
  24.  
  25.                 'Else
  26.                 '    STRSQL = "Update diagnose set first_aid = @ill, sname = @symp where first_aid = @ill"
  27.                 '    Using myCmd = New MySqlCommand(STRSQL, myConn)
  28.                 '        myConn.Open()
  29.                 '        myCmd.Parameters.AddWithValue("ill", cmbRecord.Text)
  30.                 '        myCmd.Parameters.AddWithValue("sym", symp0.Text)
  31.                 '        myCmd.Parameters.AddWithValue("sym", symp1.Text)
  32.                 '        myCmd.Parameters.AddWithValue("sym", symp2.Text)
  33.                 '        myCmd.Parameters.AddWithValue("sym", symp3.Text)
  34.                 '        myCmd.Parameters.AddWithValue("sym", symp4.Text)
  35.                 '        myCmd.Parameters.AddWithValue("sym", symp5.Text)
  36.                 '        myCmd.Parameters.AddWithValue("sym", symp6.Text)
  37.                 '        myCmd.Parameters.AddWithValue("sym", symp7.Text)
  38.                 '        myCmd.Parameters.AddWithValue("sym", symp8.Text)
  39.                 '        myCmd.Parameters.AddWithValue("sym", symp9.Text)
  40.                 '        myCmd.ExecuteNonQuery()
  41.                 '    End Using
  42.                 '    MsgBox("Record Updated")
  43.                 '    myConn.Close()
  44.             End If
  45.  
The codes marked as comment is my code for updating, but that's not working so I set it aside for the mean time. The table looks like this:
f_id| illness | symptom
1 | fever | fever
2 | fever | hot temperature
3 | fever | dizziness
4 | fever | headache
so in that case, say I chose fever in the combobox then it will display the symptoms on the 4 textboxes. If the user made changes, the Duplicate() function checks if the combobox value already have a record. If true then it will update. Say the user added another symptom, so if save button is clicked, fever will add another row with the added symptom. If false, then a new record will be added, which means new row or rows will be added in the table dependeng on the number of symptoms inputted on the textboxes. So, say 'cold' is to be added as a new record and I entered 2 symptoms, this means that I used 2 of the 10 textboxes in the form, then 2 rows will be added on the table. I already spent a day trying to make this work but failed. Please help me make this work. Any help will be greatly appreciated. Thanks in advance, Godbless
Feb 17 '13 #1
2 3931
kumsay
25 New Member
ok I'm getting closer..I can add a row in the database now but only 1. Say I entered cold as new illness then filled the 2 textboxes with symptoms, it only stores the symptom on the first textbox. So it only add 1 row with 1 symptom on the table. Also, I still get the "Parameter 'ill' has already been defined". Anybody have an idea?
Feb 17 '13 #2
Mikkeee
94 New Member
Kumsay, it looks like you keep adding to your parameter collection. You need to either add the parameters to your command before your loop and just update the values OR you need to clear them before you use AddWithValue.
Feb 17 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2424
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish, Swedish or English). There are about a dozen tables with columns that need localization. Doing this in the application level was a no-goer. It would have taken far too much time (there is a *lot* of code and unfortunately most of the...
5
18211
by: skipc | last post by:
Hi, I am stuck... I've got a popup window that displays a list in table format with links on the bottom to navigate the list <prev> 1 2 3 ... <next> When I demo'd to the users... they immediately asked if they could use the arrow keys and enter key to navigate the list. I think there must be a way to do this, but I can't figure it out.
1
6470
by: Sharon | last post by:
Hello All, Is it possible to update Sql Table through DataGrid. I have a DataGrid which is being populated through a stored procedure, all i wanted to do is to update one field (FieldName-Authorised) which has a datatype bit through DataGrid but not sure how to go about it. Any Ideas Guys on this one, your help is greatly appreciated. This is the procedure used to populate the datagrid, The primary key for the table is EntryID which...
2
2311
by: veenaaecom | last post by:
Hi, I have a table A , table B and table C. Table B is kind of a bridge to table A and table C (i.e it has common columns that bridges table A and table C) I have a colun in table A whose value is mismatching with that of table C. I need to update table A using table C but I don't have common columns except the column itself which I need to update. i need to do a join in order to update. I don's know how to write this query. If anyone can...
1
3264
by: gomathinayagam | last post by:
hai, am only beginer in c#... i am trying to connect database with webform. using a technique that the fields of the table and the controls in a form are named same...then i try get the controls and check their name with database fields names if they equal then i plan to do addition or update etc... MY PROBLEM is, i am succeed in addition, but know i try to edit the same field. i assign the datatable and made the changes in that...
10
4102
by: gagonm | last post by:
Hi I m looking for some sample example (Code) for my following scenario I have a Grid View which populates data from database say from Product Tables using dataset and dataadapter This Grid has three columns of productid ,ProductName ,Unit Price (THis is editable text box field). There is checkbox column. (Paging is enabled there are 2 pages ) There are three buttons say update and delete Now suppose I select 5 checkboxes and
3
2032
by: planethax | last post by:
I have multiple arrays that I need to insert/update database and I am not sure how to start, I think I need to use the "foreach" statement and also not sure whether or not to serialize and unserialize? this info is then going to be used to populate a table. This is what I have so far <?php $url = 'http://sports.yahoo.com/nascar/standings'; $html = file_get_contents($url);
1
3884
by: visweswaran2830 | last post by:
Hi, I want to insert href into tabel cell using javascript. Note should support all browser. I know to insert, but it support only in IE, I checked in firefox, it does not support so please help me. This is code to insert(works in IE) var myLink = document.createElement('a'); var href = document.createAttribute('href');
0
2705
by: kumardharanik | last post by:
Hi Friends, The below code is a sample code for insert, update and delete using datagrid but i need to convert the entire code for datagridview.. Plsss help me.. using System; using System.Drawing; using System.Collections; using System.ComponentModel;
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8762
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.