I am using below code to write a text file with | delimiter
int i = 0;
StreamWriter sw = null;
sw = new StreamWriter(filePath, false);
for (i = 0; i < dt.Columns.Count; i++)
{ sw.Write(dt.Columns[i].ToString() + "\t"); }
sw.WriteLine();
foreach (DataRow row in dt.Rows)
{ object[] array = row.ItemArray; for (i = 0; i < array.Length; i++)
{ sw.Write(array[i].ToString() + "\t"); }
sw.WriteLine(); }
sw.Close();
but it writes the text file with | delimiter at the end of column and row ..
How can I not write the | delimiter at the end of Colum and row
Current result
Colum1 | column2| column3|
1001 | 1002 | 1003 |
And I would like to create file without the delimiter at the end of column and row
Colum1 | column2| column3
1001 | 1002 | 1003
VulpesPosted Feb 14, 2014, 6:54 PM
j cPosted Feb 19, 2014, 11:53 AM
VulpesPosted Feb 18, 2014, 5:00 PM
I'd try doubling it:
cmd.CommandTimeOut = 60;
You can also set it to infinite:
cmd.CommandTimeOut = 0;
but I'd avoid doing that if you can.
j cPosted Feb 18, 2014, 4:42 PM
Do you think the resultset takes too long or large? how can i redove this error?
VulpesPosted Feb 18, 2014, 3:20 PM
j cPosted Feb 18, 2014, 2:45 PM
How can I fill the data table object with out put of Stored procedure
I have stored procedure Queryoutput and I would like to fill the data table object with the result of this stored procedure and qrite to a text file..
something like below..
OleDbDataAdapter A = new OleDbDataAdapter();
System.Data.DataTable dt = new System.Data.DataTable();
A.Fill(dt, "fill with output of Stored Procedure" );
{
sw.Write(dt.Columns[i].ToString());
}
sw.WriteLine();
{
{
sw.Write(array[i].ToString());
}
sw.WriteLine();
}
sw = int i = 0;StreamWriter sw = null;new StreamWriter(filePath, false);Stopwatch watch = Stopwatch.StartNew();for (i = 0; i < dt.Columns.Count; i++)if (i < dt.Columns.Count - 1) sw.Write("\t");foreach (DataRow row in dt.Rows)object[] array = row.ItemArray;for (i = 0; i < array.Length; i++)if (i < array.Length - 1) sw.Write("\t");j cPosted Feb 17, 2014, 9:58 AM
VulpesPosted Feb 16, 2014, 4:42 PM
The elapsed time is in milliseconds (a long integer) and you might want to divide that by 1000 to get the number of complete seconds and cast to an int, depending on the database column type:
There are no limitations on StreamWriter to my knowledge as it just writes the records one by one to the file. However, I'd be very surprised if doing it this way was as fast as using a native SQL Server utility such as BCP which is optimized for dealing with a large number of records.
j cPosted Feb 16, 2014, 4:01 PM
Yes. the total time it took to write records to a text file.
I am using SQL server 2008 R2 and the table is called Outputlog and name of columns : TotalRecord, TotalTime
Also, Is there any limitations of using StreamWriter in .net i.e record size, data size,etc
The data can be quite large( millions of record) and I was wondering if there are any limitations of uinsg this class in terms of how many records you can write compare to other Database tool such as BCP, SQLCMD,etc...
Thanks
VulpesPosted Feb 16, 2014, 3:43 PM
When you say the total time do you mean the time that it took to write these records to the text file?
As regards the database, which one do you use and what's the name of the table and the columns for these two items?
j cPosted Feb 16, 2014, 1:55 PM
how can i capture the number of record that got created and the total time and insert into DAtabase table?
Thanks
j cPosted Feb 14, 2014, 10:55 PM