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: -
Call Connect()
-
Dim str As String
-
str = "Select sname from diagnose where first_aid = @ill"
-
cmd.Parameters.AddWithValue("ill", cmbRecord.Text)
-
cmd.Connection = myConn
-
cmd.CommandText = str
-
dtr = cmd.ExecuteReader
-
-
Dim symptoms As New List(Of String)
-
While dtr.Read()
-
symptoms.Add(dtr("sname"))
-
End While
-
'set available symptoms
-
Dim arrayOfTextboxes() As TextBox = {symp0, symp1, symp2, symp3, symp4, symp5, symp6, symp7, symp8, symp9}
-
Dim i As Integer = 0
-
For i = 0 To symptoms.Count - 1
-
arrayOfTextboxes(i).Text = symptoms(i)
-
Next
-
'clear other textboxes
-
For j = i To UBound(arrayOfTextboxes)
-
arrayOfTextboxes(j).Text = String.Empty
-
Next
-
myConn.Close()
-
and here's my code for inserting or updating. I get error "Parameter 'ill' has already been defined." -
Call Connect()
-
If Duplicate() = False Then
-
Dim dt As New DataTable("diagnose")
-
Dim row As DataRow
-
Dim arrayOfTextboxes() As TextBox = {symp0, symp1, symp2, symp3, symp4, symp5, symp6, symp7, symp8, symp9}
-
Dim symptoms As New List(Of String)
-
STRSQL = "insert into diagnose values (@ill, @sym)"
-
Using myCmd = New MySqlCommand(STRSQL, myConn)
-
myConn.Open()
-
-
Dim i As Integer = 0
-
For i = 0 To arrayOfTextboxes.Count - 1
-
If String.IsNullOrEmpty(arrayOfTextboxes(i).Text) Then Continue For
-
If arrayOfTextboxes(i).Text <> "" Then
-
myCmd.Parameters.AddWithValue("ill", cmbRecord.Text)
-
myCmd.Parameters.AddWithValue("sym", arrayOfTextboxes(i).Text)
-
row = dt.NewRow()
-
myCmd.ExecuteNonQuery()
-
End If
-
Next
-
MsgBox("Record Added")
-
myConn.Close()
-
End Using
-
-
'Else
-
' STRSQL = "Update diagnose set first_aid = @ill, sname = @symp where first_aid = @ill"
-
' Using myCmd = New MySqlCommand(STRSQL, myConn)
-
' myConn.Open()
-
' myCmd.Parameters.AddWithValue("ill", cmbRecord.Text)
-
' myCmd.Parameters.AddWithValue("sym", symp0.Text)
-
' myCmd.Parameters.AddWithValue("sym", symp1.Text)
-
' myCmd.Parameters.AddWithValue("sym", symp2.Text)
-
' myCmd.Parameters.AddWithValue("sym", symp3.Text)
-
' myCmd.Parameters.AddWithValue("sym", symp4.Text)
-
' myCmd.Parameters.AddWithValue("sym", symp5.Text)
-
' myCmd.Parameters.AddWithValue("sym", symp6.Text)
-
' myCmd.Parameters.AddWithValue("sym", symp7.Text)
-
' myCmd.Parameters.AddWithValue("sym", symp8.Text)
-
' myCmd.Parameters.AddWithValue("sym", symp9.Text)
-
' myCmd.ExecuteNonQuery()
-
' End Using
-
' MsgBox("Record Updated")
-
' myConn.Close()
-
End If
-
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
2 3931
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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.
|
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...
|
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...
|
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...
| |
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
|
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);
|
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');
|
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;
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |