Может ли кто-нибудь дать мне шаг, чтобы решить эту ошибку при получении вывода. Новое в кодировании.
Шаг 1 : Использование Json / Javascript для вызова метода из файла .cs (c#)
var markers = JSON.parse('<%=ConvertDataTabletoString("NewGetTaskWorkPercentage1",null) %>');
Шаг 2 :
.cs file code for method ConvertDataTabletoString
public string ConvertDataTabletoString(string Sql, string prjno)
{
//var qprojectno = Request.QueryString["ProjectNo"].ToString();
param1.Value = "P-2020-0009"; //aspx hidden field
DataTable dt = new DataTable();
using (con = new SqlConnection(connectionString))
{
using (cmd = new SqlCommand(Sql, con))
{
string connetionString = "Data Source = ; Initial Catalog = DashBoardDB; User ID = ; Password = ";
SqlConnection connection = new SqlConnection(connetionString);
connection.Open();
string sql1 = "SELECT InstanceId,Module,SubModule,Process FROM Xtable WHERE ProjectNo=" + "'" + param1.Value + "'"+ "and instanceid='aabed4df-3e91-41c0-8788-2e7d31eecfd8'";
SqlCommand command = new SqlCommand(sql1, connection);
command.CommandTimeout = 600;
SqlDataReader dataReader = command.ExecuteReader();
serializedResult = " ";
while (dataReader.Read())
{
string strInsId = " ";
string strProcess = "";
strInsId = dataReader["InstanceId"].ToString();
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
cmd.Parameters.Add(new SqlParameter("@ProjectNo", prjno));
cmd.Parameters.Add(new SqlParameter("@InstanceId", strInsId));
sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
foreach (DataRow dr in dt.Rows)
{
Console.WriteLine(dr + " " + dt.Rows);
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rows.Add(row);
}
serializedResult = serializer.Serialize(rows);
serializedResult += serializer.Serialize(rows); **two times concatenating**
con.Close();}
dataReader.Close();
command.Dispose();
connection.Close();
return serializedResult;
}
}
}
Шаг 3 : Прикрепленное изображение
На стороне клиента, как разбить эти значения на массивы. Я требовал вывода, как это. Как я могу получить вывод в массиве и длину массива на стороне клиента. Спасибо
Массив 1:
[{"Task":"Feature 1.1.3","OverallSubtaskDuration":17.00,"ActualStart":"2019/10/18","ActualEnd":"2020/03/13","OverallSubtaskPercentage":283.33},
{"Task":"Feature 1.1.3","OverallSubtaskDuration":8.00,"ActualStart":"2019/10/18","ActualEnd":"2019/10/25","OverallSubtaskPercentage":133.33},
{"Task":"Feature 1.1.3","OverallSubtaskDuration":3.00,"ActualStart":"2020/03/11","ActualEnd":"2020/03/13","OverallSubtaskPercentage":50.00},
{"Task":"Feature 1.1.3","OverallSubtaskDuration":3.00,"ActualStart":"2019/10/27","ActualEnd":"2019/10/29","OverallSubtaskPercentage":50.00}]
Массив 2:
[{"Task":"Feature 1.1.3","OverallSubtaskDuration":17.00,"ActualStart":"2019/10/18","ActualEnd":"2020/03/13","OverallSubtaskPercentage":283.33},
{"Task":"Feature 1.1.3","OverallSubtaskDuration":8.00,"ActualStart":"2019/10/18","ActualEnd":"2019/10/25","OverallSubtaskPercentage":133.33},
{"Task":"Feature 1.1.3","OverallSubtaskDuration":3.00,"ActualStart":"2020/03/11","ActualEnd":"2020/03/13","OverallSubtaskPercentage":50.00},
{"Task":"Feature 1.1.3","OverallSubtaskDuration":3.00,"ActualStart":"2019/10/27","ActualEnd":"2019/10/29","OverallSubtaskPercentage":50.00}]