I have a plain text file that contains one column of numbers, and in a web client take the numbers and transfer them into a SQL Database. After retrieving the file, I store the contents in a temporary DataTable, then using SqlBulkCopy, attempt to transfer the DataTable to the database. However, once I run the web client and import the file, the program hangs. The code is listed below for what I've done so far.
Transferring Files to DataTable
private DataTable readTextFile()
{
DataTable dt = new DataTable();
FileUpload file = new FileUpload();
dt.Columns.Add("Claim Number", typeof(Int32));
file = (FileUpload)grdCriteria.FindControl("exportUpload");
StreamReader read = new StreamReader(file.PostedFile.FileName);
while ((read.ReadLine()) != null)
dt.Rows.Add((Int32.Parse(read.ReadLine())));
return dt;
}
Insert DataTable into SQL Database
DataTable dt = readTextFile();
SqlBulkCopy bk = new SqlBulkCopy(Profile.ConnectionKey.CAM);
bk.DestinationTableName = dt.TableName;
bk.WriteToServer(dt);
Thanks!