How to add data to sql but for one id and more than one data ?
- by Phsika
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;
}