У меня есть DataTable, который содержит 3000 записей. Я хочу выполнить репликацию между Android SQLite и MS SQL. Я хочу конвертировать набор данных в JSON. Я не могу передать это количество данных. Так что я хочу взять 500 записей 1-й раз 2-й раз следующие 500 записей. Также хочу сделать. Поэтому я использовал Linq для выбора записей из DataTable.
public String ConverDataSetToJson(DataSet dsDownloadJson,int currentSplit)
{
StringBuilder Sb = new StringBuilder();
int start = 0;
int end =500;
int chk = 0;
string json = "";
int currentChk = currentSplit;
int total =0;
DataTable dt1 = new DataTable();
if (dsDownloadJson.Tables.Count > 0)
{
Sb.Append("{");
foreach (DataTable dt in dsDownloadJson.Tables)
{
DataTable dtDownloadJson = dt;
total = dtDownloadJson.Rows.Count;
// If row count less than 500, then take that amount
if (dtDownloadJson.Rows.Count < 500)
{
end = dtDownloadJson.Rows.Count;
}
//number of split data set
if (chk == 0)
{
if (dtDownloadJson.Rows.Count > 500)
{
if ((dtDownloadJson.Rows.Count / 500) == 0)
{
chk = dtDownloadJson.Rows.Count / 500;
}
else
{
chk = dtDownloadJson.Rows.Count / 500 + 1;
}
}
else
{
chk = 1;
}
currentChk = 1;
}
else
{
currentChk = currentChk + 1;
start = currentChk * 500;
end = start + 500;
currentChk = chk;
}
var AllProducts = dtDownloadJson.AsEnumerable();
if (AllProducts.Count() > 0)
{
var query1 = (from c in AllProducts select c).Skip(0);
query1 = (from c in query1 select c).Take((end - start) + 1);
int res = query1.Count();
Console.WriteLine("---------" + res);
if (query1.Count() > 0)
{
dtDownloadJson.Rows.Clear();
dt1 = query1.CopyToDataTable();
int count = dt1.Rows.Count;
json = JsonConvert.SerializeObject(dt1, Formatting.Indented);
}
}
}
}
return json;
}
Пожалуйста, помогите мне, это выдает ошибку The Source contain no data source. When Go to CopyToDataTable
в строке.