How to add data to sql but for one id and more than one data ?
        Posted  
        
            by Phsika
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Phsika
        
        
        
        Published on 2010-05-06T08:01:27Z
        Indexed on 
            2010/05/06
            8:08 UTC
        
        
        Read the original article
        Hit count: 247
        
i have one id and more filepaths.forexample:
StudyInstanceUid:123456
FilePath: C:/a.jpg C:/b.jpg C:/c.jpg C:/d.jpg C:/e.jpg
Result added table:
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
  public bool AddDCMPath2(string StudyInstanceUid, 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("@StudyInstanceUid", StudyInstanceUid);
                    cmd.Parameters.AddWithValue("@FilePath", filepath);
                    cmd.ExecuteNonQuery();
                }
            }
            finally
            {
                if((con!=null))
                con.Dispose();
                if((cmd!=null))
                cmd.Dispose();
            }
            return true;
        }© Stack Overflow or respective owner