Hi,
I need to insert multiple files from front-end in the same datacolumn in DB using c#.
& also need to retrieve from DB to UI.
Please help me out.
My code is as follows...
I need to insert multiple files from front-end in the same datacolumn in DB using c#.
& also need to retrieve from DB to UI.
Please help me out.
My code is as follows...
Code:
string filePath = fDialog.FileName;
string[] fileNames = fDialog.FileNames;
string filename = System.IO.Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
byte[] FilesData=null;
List<byte> FileData = new List<byte>();
List<string> AllFiles = new List<string>();
for (int i = 0; i < fileNames.Length; i++)
{
AllFiles.Add(fileNames[i]);
}
foreach (string str in AllFiles)
{
FileStream fs = new FileStream(str, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
FilesData = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
}
try
{
connection.Open();
string query = "insert into TableName(IDVERSION,FILENAME,FILE) values(@Idversion,@FileName,@File);commit;";
command = new DB2Command(query, connection);
command.Parameters.Add("@Idversion", DB2Type.Integer).Value = 0012013;
command.Parameters.Add("@FileName", DB2Type.VarChar).Value = AllFiles.ToString();
command.Parameters.Add("@File", DB2Type.Binary).Value = FilesData;
command.ExecuteNonQuery();
}
catch (Exception)
{ }
finally
{
connection.Close();
}
Comment