G
Guest
Hi:
I'm trying to add rows to a datatable from an array, but due to lack of
brain power, am unable to make this work. I'm being told that I don't have
enough columns (I only want one column at this point.) Anyone have any ideas?
Thanks
====================================================
private void button1_Click(object sender, System.EventArgs e)
{
WebRequest req =
WebRequest.Create("http://www.sec.gov/Archives/edgar/daily-index/" +
"company." + "20041222" + ".idx"); // Create the Request object
WebResponse response = req.GetResponse(); //Create
the Response object
Stream stream = response.GetResponseStream(); //Create a
Stream
StreamReader sr = new StreamReader(stream); //Open the file in a
stream reader
//StreamReader sr = new StreamReader("c:\\test.txt"); //Read
From A File instead of a webrequest
DataSet result = new DataSet(); //The DataSet to Return
string AllData1 = sr.ReadToEnd(); //Read the rest
of the data in the file.
string[] rows = AllData1.Split("\r\n".ToCharArray()); //Split
off each row at the Carriage Return/Line Feed
result.Tables.Add("MyNewTable"); //Add DataTable to hold the
DataSet
result.Tables["MyNewTable"].Columns.Add("Data"); //Add a
single column
result.Tables["MyNewTable"].Rows.Add(rows); //Add the
rows to the DataTable/DataSet
for (int i = 1; i <= 8; i++)
{
result.Tables["MyNewTable"].Rows.RemoveAt(i); //Remove first 8 rows
from the DataTable/DataSet
}
dataGrid1.SetDataBinding(result, "MyNewTable"); //Binds DataGrid to
DataSet,displaying datatable.
}
I'm trying to add rows to a datatable from an array, but due to lack of
brain power, am unable to make this work. I'm being told that I don't have
enough columns (I only want one column at this point.) Anyone have any ideas?
Thanks
====================================================
private void button1_Click(object sender, System.EventArgs e)
{
WebRequest req =
WebRequest.Create("http://www.sec.gov/Archives/edgar/daily-index/" +
"company." + "20041222" + ".idx"); // Create the Request object
WebResponse response = req.GetResponse(); //Create
the Response object
Stream stream = response.GetResponseStream(); //Create a
Stream
StreamReader sr = new StreamReader(stream); //Open the file in a
stream reader
//StreamReader sr = new StreamReader("c:\\test.txt"); //Read
From A File instead of a webrequest
DataSet result = new DataSet(); //The DataSet to Return
string AllData1 = sr.ReadToEnd(); //Read the rest
of the data in the file.
string[] rows = AllData1.Split("\r\n".ToCharArray()); //Split
off each row at the Carriage Return/Line Feed
result.Tables.Add("MyNewTable"); //Add DataTable to hold the
DataSet
result.Tables["MyNewTable"].Columns.Add("Data"); //Add a
single column
result.Tables["MyNewTable"].Rows.Add(rows); //Add the
rows to the DataTable/DataSet
for (int i = 1; i <= 8; i++)
{
result.Tables["MyNewTable"].Rows.RemoveAt(i); //Remove first 8 rows
from the DataTable/DataSet
}
dataGrid1.SetDataBinding(result, "MyNewTable"); //Binds DataGrid to
DataSet,displaying datatable.
}