Convert DataSet To String In C#.Net

private string GetTemplate()
{
string sReturnData = string.Empty;
try
{

string connectionString = “Provider=Microsoft.Jet.OleDb.4.0; data source=c:\\YRF.XLS; Extended Properties=Excel 8.0;”;
string selectString = “SELECT * FROM [new$]”;

System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
System.Data.OleDb.OleDbDataAdapter adp = new System.Data.OleDb.OleDbDataAdapter(selectString,connectionString);
DataSet ds=new DataSet();
adp.Fill(ds);
System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection(connectionString);
System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(selectString, con);

con.Open();
System.Data.OleDb.OleDbDataReader theData = cmd.ExecuteReader();

Int32 i = 0;
String str = “”;
System.Data.DataTable dt = new System.Data.DataTable();
dt = ds.Tables[0];
str += “”;
while (i < dt.Rows.Count)
{
str += "” + dt.Rows[i][0].ToString() + “” + “” + dt.Rows[i][1].ToString() + “” + “” + dt.Rows[i][2].ToString() + “” + “” + dt.Rows[i][3].ToString() + “” + “” + dt.Rows[i][4].ToString() + “” + “” + dt.Rows[i][5].ToString() + “” + “” + dt.Rows[i][6].ToString() + “” + “” + dt.Rows[i][7].ToString() + “” + “” + dt.Rows[i][8].ToString() + “” + “” + dt.Rows[i][9].ToString() + “”;
sReturnData += str;
i++;
}

}
catch (Exception ex)
{
lblError.Text = ex.Message;
sReturnData = “No Value”;
}

sReturnData += “”;
return sReturnData;
}

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s