Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am doing a research project. I have text values like s1, s2, s2, s4 etc in 100s in single column (multiplr rows). Now i want to save these values in a database.

C#
foreach (ListViewItem item in listBox2.Items)
            try
            {
                
               SqlCommand cmd =new System.Data.SqlClient.SqlCommand();
                comd.CommandText= ("INSERT INTO Symptom(s1, s2, s2, s4 )VALUES(@s1,@s2,@s3), s4");
                comd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            comd.Connection.Close();
            comd.Dispose();


Can some one help what is the best way to get these strings into database and retrieve them in a single column.
Thanks in advace in millions.
Posted
Updated 3-Mar-13 16:30pm
v2
Comments
David_Wimbley 3-Mar-13 23:20pm    
Not sure i quite understand your question.

Do you mean your insert that you provided works but you want to know how to retrieve all columns in "one"?

SELECT s1 + s2 + s2 + s4 AS OneColumnAllResults FROM Symptom

Is that what you want?
RDBurmon 3-Mar-13 23:43pm    
Do you want to save those 100 values in one single row of database table ?
or 100 rows where each value in each row

Give me your "Symptom" table structure to understand your problem better ?
Dr Satti 5-Mar-13 21:26pm    
Thanks. I have values already in a listbox, single column multiple rows. Now I want to store or save or insert in a table. The problem is let say we have three rats. One held as a control, one exposed to radiation one to chemical. Now we want to see the effects on them after one week, two weeks, 3 weeks etc. These epigenetic effects are let say s1, s2, s3, ... s10 for one rat. I want to store them. I want to add for second week, then third week etc. with date. Now I want to compare them side by side.

1 solution

Hello Try this

C#
foreach (string list in listBox1.Items)
{

          
}
 
Share this answer
 
Comments
Dr Satti 5-Mar-13 21:28pm    
The message comes Must declare the scalar variable @s1. Did not work. Any alternate solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900