Answer the question
In order to leave comments, you need to log in
How to automatically select the data type?
Good afternoon!
There is some function:
public List<List<string>> DateToLis(string date)
{
DataTable dt = Get("SELECT service.FullName,asuiogv.fl_req_peper + asuiogv.fl_req_other,asuiogv.fl_req_epgu,asuiogv.fl_req_email,asuiogv.fl_req_ved,asuiogv.fl_z_peper + asuiogv.fl_z_other,asuiogv.fl_z_epgu,asuiogv.fl_z_email,asuiogv.fl_z_ved,asuiogv.ul_req_peper + asuiogv.ul_req_other,asuiogv.ul_req_epgu,asuiogv.ul_req_email,asuiogv.ul_req_ved,asuiogv.ul_z_peper + asuiogv.ul_z_other,asuiogv.ul_z_epgu,asuiogv.ul_z_email,asuiogv.ul_z_ved FROM asuiogv INNER JOIN service ON service.id = asuiogv.id_service where period='" + date + "';");
List<List<string>> data = new List<List<string>>();
for (int i = 0; i < dt.Rows.Count-1; i++)
{
List<string> list = new List<string>();
for (int j = 0; j < dt.Columns.Count-1; j++)
{
list.Add(dt.Rows[i].Field<string>(dt.Columns[j].Caption));//здесь необходимо за место string автоматически подбирать тип данных в зависимости от БД
}
data.Add(list);
}
return data;
}
list.Add(dt.Rows[i].Field<string>(dt.Columns[j].Caption));
string changed depending on the table data, i.e. int64, int or string. TypeCode tc=Type.GetTypeCode(dt.Columns[dt.Columns[j].Caption)].DataType);
but when substituting instead of string, it gives an error. Answer the question
In order to leave comments, you need to log in
Of course, I would like to say a little foul language, but I will probably gather my strength. How many fields do you have in the output? ten? If there were 500 of them, then your problem would be clear, but everything is solved easier. You must have an entity class whose object is created based on the received data.
Gather your strength and write prop1 = col1, prop2 = col2, etc. Each individual field has its own type, and if you don't have surprises there, everything will converge fine. List<List<string>>
this is not a type - this is crap. No entity data.
Take advantage of C#'s "everything is an object":
1) replace List<List<string>>
with List<List<object>>
;
2) dt.Rows[i].Field<string>(dt.Columns[j].Caption)
replace with dt.Rows[i][dt.Columns[j]]
;
3) explain the purpose of this entire code, because it resembles a transfusion from empty to empty, and List<List<object>>
this is a bomb by definition.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question