今天在做一個需求的時候
Datatable 到 string
public static string DataTableToString(DataTable dt)
{
//!@&
//為了防止連接字符串不在DataTable數據中存在
StringBuilder strData = new StringBuilder();
StringWriter sw = new StringWriter();
//DataTable 的當前數據結構以 XML 架構形式寫入指定的流
dt
strData
sw
strData
for (int i =
{
DataRow row = dt
if (i >
{
strData
}
for (int j =
{
if (j >
{
strData
}
strData
}
}
return strData
}
string 到Datatable
public static DataTable StringToDataTable(string strdata)
{
if (string
{
return null;
}
DataTable dt = new DataTable();
string[] strSplit = {
string[] strRow = {
string[] strColumn = {
string[] strArr = strdata
StringReader sr = new StringReader(strArr[
dt
sr
string strTable = strArr[
if (!string
{
string[] strRows = strTable
for (int rowIndex =
{
string vsRow = strRows[rowIndex]; //取行的字符串
string[] vsColumns = vsRow
dt
}
}
return dt;
}
From:http://tw.wingwit.com/Article/program/net/201311/13183.html