I've read and split a delimited text file into a dataset.
It looks fine in a datagrid (5 columns and 5,000 rows),
but I've been trying, without success, to then insert
the resulting dataset called "result" into a single sql
table that has an auto-increment and PK column called ID,
as well as the 5 columns from the dataset.
Any suggestions on a way to perform the insert of the
"result" dataset into the sql table?
Thanks,
Paul
=============== =============== =============== =============== =============== =============== ========
StreamReader sr = new StreamReader("C :\\test.txt"); //Read From A
File instead of a webrequest
DataSet result = new DataSet(); //The DataSet to Return
result.Tables.A dd("MyNewTable" ); //Add DataTable to hold the DataSet
result.Tables["MyNewTable "].Columns.Add("C ompanyName"); //Add a single
column to the DataTable
result.Tables["MyNewTable "].Columns.Add("F ormType"); //Add a single
column
result.Tables["MyNewTable "].Columns.Add("C IK"); //Add a single
column
result.Tables["MyNewTable "].Columns.Add("D ateFiled"); //Add a single
column
result.Tables["MyNewTable "].Columns.Add("S ECWebAddress"); //Add a single
column
string AllData1 = sr.ReadToEnd(); //Read the rest of the
data in the file.
string[] rows = AllData1.Split( "\n".ToCharArra y()); //Split off each
row at the Line Feed
foreach(string r in rows) //Now add each row to the
DataSet
{
string delimStr1 = "\t";
string[] items = r.Split(delimSt r1.ToCharArray( )); //Split the row at the
delimiter
result.Tables["MyNewTable "].Rows.Add(items ); //Add the item
}
for (int i = 1; i <= 11; i++) //Remove first 8
rows from the DataTable/DataSet
{
result.Tables["MyNewTable "].Rows.RemoveAt( 0);
}
dataGrid1.SetDa taBinding(resul t, "MyNewTable "); //Binds DataGrid to
DataSet,display ing datatable
It looks fine in a datagrid (5 columns and 5,000 rows),
but I've been trying, without success, to then insert
the resulting dataset called "result" into a single sql
table that has an auto-increment and PK column called ID,
as well as the 5 columns from the dataset.
Any suggestions on a way to perform the insert of the
"result" dataset into the sql table?
Thanks,
Paul
=============== =============== =============== =============== =============== =============== ========
StreamReader sr = new StreamReader("C :\\test.txt"); //Read From A
File instead of a webrequest
DataSet result = new DataSet(); //The DataSet to Return
result.Tables.A dd("MyNewTable" ); //Add DataTable to hold the DataSet
result.Tables["MyNewTable "].Columns.Add("C ompanyName"); //Add a single
column to the DataTable
result.Tables["MyNewTable "].Columns.Add("F ormType"); //Add a single
column
result.Tables["MyNewTable "].Columns.Add("C IK"); //Add a single
column
result.Tables["MyNewTable "].Columns.Add("D ateFiled"); //Add a single
column
result.Tables["MyNewTable "].Columns.Add("S ECWebAddress"); //Add a single
column
string AllData1 = sr.ReadToEnd(); //Read the rest of the
data in the file.
string[] rows = AllData1.Split( "\n".ToCharArra y()); //Split off each
row at the Line Feed
foreach(string r in rows) //Now add each row to the
DataSet
{
string delimStr1 = "\t";
string[] items = r.Split(delimSt r1.ToCharArray( )); //Split the row at the
delimiter
result.Tables["MyNewTable "].Rows.Add(items ); //Add the item
}
for (int i = 1; i <= 11; i++) //Remove first 8
rows from the DataTable/DataSet
{
result.Tables["MyNewTable "].Rows.RemoveAt( 0);
}
dataGrid1.SetDa taBinding(resul t, "MyNewTable "); //Binds DataGrid to
DataSet,display ing datatable