views:

39

answers:

2

i have one id and more filepaths.forexample:

id:123456

FilePath: C:/a.jpg C:/b.jpg C:/c.jpg C:/d.jpg C:/e.jpg

Result must be:
123456|C:/a.jpg
123456|C:/b.jpg
123456|C:/c.jpg
123456|C:/d.jpg
123456|C:/e.jpg

How can i add more than one path for one id

But My result is :


123456|C:/e.jpg

i need others

  public bool AddDCMPath2(string id, string[] FilePath)
        {
            SqlConnection con = new SqlConnection("Data Source=(localhost);Initial Catalog=ImageServer; User ID=sa; Password=GENOTIP;");
            SqlCommand cmd = new SqlCommand("INSERT INTO StudyDCM (StudyInstanceUid,FilePath) VALUES (@StudyInstanceUid,@FilePath)", con);
            try
            {
                con.Open();
                cmd.CommandType = CommandType.Text;


                foreach (string filepath in FilePath)
                {
                    cmd.Parameters.AddWithValue("@id", id);
                    cmd.Parameters.AddWithValue("@FilePath", filepath);
                    cmd.ExecuteNonQuery();
                }
            }
            finally
            {
                if((con!=null))
                con.Dispose();
                if((cmd!=null))
                cmd.Dispose();
            }
            return true;
        }
+1  A: 

You must serialise them into a single string, i.e. join the paths with a separator such as '|', then input the combined string into the database. When reading, get the combined string and split it, then use the paths.

Delan Azabani
this C# code add only last one. but i need whole
Phsika
My answer is how to fix the problem.
Delan Azabani
A: 
 foreach (string filepath in FilePath)
                {
                    cmd.Parameters.AddWithValue("@StudyInstanceUid", StudyInstanceUid);
                    cmd.Parameters.AddWithValue("@FilePath", filepath);
                    cmd.ExecuteNonQuery();
                   cmd.Parameters.Clear();

                }
Phsika