Import & Export Data

Posted by Pravesh Singh under Others on 12/8/2011 | Points: 10 | Views : 1081 | Status : [Member] | Replies : 5
Hello Everyone,
I have facing one problem, Actually I want to know; Is there any tool through which can import data of different file (such as csv, txt, sql, xls file etc.) and perform some filtration either used by database query or manually and then export this data to file, this file may be in csv, txt, sql, xls or whatever you want.

Please give me your valuable suggestion.

Thanks in advance!!

Pravesh Singh


Responses

Posted by: Blessyjees on: 12/8/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

You can write code for each file. Please see the below example to export data to csv file
 DataTable dt = _dsExportTables.Tables[i]; //here we get data from db to datatable

string strFileName = Server.MapPath(".") + @"\ExportCSV\"+ strTableName + ".csv";

strCSVFilestoZip = strCSVFilestoZip + "," + strFileName;

if (File.Exists(strFileName))
{
File.Delete(strFileName);
}

StreamWriter writer = File.CreateText(strFileName);
for (int j = 0; j <= dt.Columns.Count - 1; j++)
{
writer.Write("\"" + dt.Columns[j].ToString() + "\"");
writer.Write("\t");
}
writer.Write(Environment.NewLine);

foreach (DataRow dr in dt.Rows)
{
foreach (DataColumn dc in dr.Table.Columns)
{
writer.Write("\"" + ((dr[dc] != null)?dr[dc].ToString ().Replace("\"","\"\""):dr[dc]) + "\"");
writer.Write("\t");
}

writer.Write(Environment.NewLine);

}
writer.Flush();
writer.Close();


Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Pravesh Singh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: BhupendarSingh on: 12/9/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Pravesh,
The best option to resolve this problem is ms-excel, because of ms-excel has been provide to export data into many format. But as you have written, you want to import or export .sql file then to do it you must have a sql environment where you could fire sql query to filtration data. There are lots of tool in the market which performs data converting task. I have used a such type of tool since last month (name is MindStick Data Converter ). Since it is free charge tool so you can easily download and used it. I don't have the exact download path of this tool but i have the website url where you could find out it.

Website URL: http://mindstick.com

I hope it might be useful for you.

Bhupendar Singh

Pravesh Singh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Cnagasa on: 12/9/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

we can write this code u get the data from the database tables

DataTable myTable = (DataTable)ViewState[TABLE_KEY];

if (myTable.Rows.Count > 0)
{
StringBuilder sb = new StringBuilder();
sb.Append("<table cellspacing=\"0\" cellpadding=\"4\" rules=\"all\" bordercolor=\"#CCCCCC\" border=\"1\" style=\"color:Black;background-color:White;border-color:#CCCCCC;border-width:1px;border-style:Solid;font-family:Tahoma;font-size:8pt;height:24px;border-collapse:collapse;\">");

sb.Append(" <tr style=\"color:White;background-color:#005500;font-weight:bold;\">");

sb.Append(" <td align=\"Center\">");

sb.Append(" Sl.No. ");
sb.Append(" </td>");

for (int llngCol = 0; llngCol < myTable.Columns.Count - lintHideColCount; llngCol++)
{
sb.Append(" <td align=\"Center\">");
sb.Append(" " + myTable.Columns[llngCol].ColumnName + "");
sb.Append(" </td>");
}

sb.Append("</tr>");
int i = 1;
foreach (DataRow objDR in myTable.Rows)
{
sb.Append(" <tr class=\"body\"> ");
sb.Append(" <td align=\"right\">");
sb.Append("" + i + "");
sb.Append(" </td> ");

for (int llngCol = 0; llngCol < myTable.Columns.Count - lintHideColCount; llngCol++)
{
switch (myTable.Columns[llngCol].DataType.ToString())
{
case "System.Int32":
sb.Append(" <td align=\"right\">");
sb.Append(" " + objDR[llngCol] + "");
break;
case "System.Double":
sb.Append(" <td align=\"right\">");
sb.Append(" " + objDR[llngCol] + "");
break;
case "System.Decimal":
sb.Append(" <td align=\"right\">");
sb.Append(" " + objDR[llngCol] + "");
break;
case "System.DateTime":
sb.Append(" <td align=\"center\">");
sb.Append(" " + (objDR[llngCol].ToString().Length == 0 ? "" : DateTime.Parse(objDR[llngCol].ToString()).ToString("dd-MMM-yyyy")) + "");
break;
case "System.String":
sb.Append(" <td align=\"left\">");
sb.Append(" " + objDR[llngCol] + "");
break;
default:
sb.Append(" <td align=\"center\">");
sb.Append(" " + objDR[llngCol] + "");
break;
}
sb.Append(" </td>");
}
sb.Append(" </tr>");
i++;
}
sb.Append("</table>");

Response.Clear();
Response.Charset = "";
//Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=Pending.xls");
Response.Write(sb.ToString());
Response.End();
}
else
lblCount.Text = "No Records Found";

Regard's
Sudarshan.C

sudarshan.c

Pravesh Singh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SummiRS on: 2/16/2012 [Member] Starter | Points: 25

Up
0
Down
Hello,
what about method is this article?
http://www.codeproject.com/Articles/151789/Export-Data-to-Excel-Word-PDF-without-Automation-f
I think that the wizard in this article may be helpful for you.

Pravesh Singh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/16/2012 [Member] Silver | Points: 25

Up
0
Down

You can create SSRS 2008 Report from which you can export to any of these formats(excel,csv,txt,doc,etc)

Thanks,
Sanjay

Pravesh Singh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response