DataTable Data as Pipe("|") Sepeated:
Its true that we will have many requirements specially when we want to share data between machines in http request/response , then we have to go for this technique:-----
public object ReturnDataTableWithPipeSeparated()
{
try
{
StringBuilder sb = new StringBuilder();
DataSet ds = GetDatatoFillinDataSetIlyas()//fill your data
int DsCount = ds.Tables.Count;
for (int i = 0; i < ds.Tables.Count; i++)
{
for (int j = 0; j < ds.Tables[i].Rows.Count; j++)
{
if (ds.Tables[i].Rows.Count > 0)
{
for (int k = 0; k < ds.Tables[i].Columns.Count; k++)
{
if (ds.Tables[i].Rows[j][k].ToString() != "")
{
sb.Append(ds.Tables[i].Rows[j][k].ToString());
}
else
{
sb.Append("\t");
}
if (k < ds.Tables[i].Columns.Count - 1)
sb.Append('|');
}
}
sb.Append('\n');
}
}
return sb;
}
catch (Exception)
{
throw;
}
}
Its true that we will have many requirements specially when we want to share data between machines in http request/response , then we have to go for this technique:-----
public object ReturnDataTableWithPipeSeparated()
{
try
{
StringBuilder sb = new StringBuilder();
DataSet ds = GetDatatoFillinDataSetIlyas()//fill your data
int DsCount = ds.Tables.Count;
for (int i = 0; i < ds.Tables.Count; i++)
{
for (int j = 0; j < ds.Tables[i].Rows.Count; j++)
{
if (ds.Tables[i].Rows.Count > 0)
{
for (int k = 0; k < ds.Tables[i].Columns.Count; k++)
{
if (ds.Tables[i].Rows[j][k].ToString() != "")
{
sb.Append(ds.Tables[i].Rows[j][k].ToString());
}
else
{
sb.Append("\t");
}
if (k < ds.Tables[i].Columns.Count - 1)
sb.Append('|');
}
}
sb.Append('\n');
}
}
return sb;
}
catch (Exception)
{
throw;
}
}
No comments:
Post a Comment