asp DataTable에 열 및 행을 추가하는 세 가지 방법
#region :
DataTable tblDatas = new DataTable("Datas");
DataColumn dc = null;
dc = tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
dc.AutoIncrement = true;//
dc.AutoIncrementSeed = 1;// 1
dc.AutoIncrementStep = 1;// 1
dc.AllowDBNull = false;
dc = tblDatas.Columns.Add("Product", Type.GetType("System.String"));
dc = tblDatas.Columns.Add("Version", Type.GetType("System.String"));
dc = tblDatas.Columns.Add("Description", Type.GetType("System.String"));
DataRow newRow;
newRow = tblDatas.NewRow();
newRow["Product"] = " ";
newRow["Version"] = "2.0";
newRow["Description"] = " ";
tblDatas.Rows.Add(newRow);
newRow = tblDatas.NewRow();
newRow["Product"] = " ";
newRow["Version"] = "3.0";
newRow["Description"] = " ";
tblDatas.Rows.Add(newRow);
#endregion
#region :
DataTable tblDatas = new DataTable("Datas");
tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
tblDatas.Columns[0].AutoIncrement = true;
tblDatas.Columns[0].AutoIncrementSeed = 1;
tblDatas.Columns[0].AutoIncrementStep = 1;
tblDatas.Columns.Add("Product", Type.GetType("System.String"));
tblDatas.Columns.Add("Version", Type.GetType("System.String"));
tblDatas.Columns.Add("Description", Type.GetType("System.String"));
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
tblDatas.Rows.Add(new object[] { null, "a", "b", "c" });
#endregion
#region :
DataTable table = new DataTable();
// table
DataColumn priceColumn = new DataColumn();
priceColumn.DataType = System.Type.GetType("System.Decimal");//
priceColumn.ColumnName = "price";//
priceColumn.DefaultValue = 50;//
// table
DataColumn taxColumn = new DataColumn();
taxColumn.DataType = System.Type.GetType("System.Decimal");
taxColumn.ColumnName = "tax";//
taxColumn.Expression = "price * 0.0862";// ,
// table
DataColumn totalColumn = new DataColumn();
totalColumn.DataType = System.Type.GetType("System.Decimal");
totalColumn.ColumnName = "total";
totalColumn.Expression = "price + tax";// ,
// table
table.Columns.Add(priceColumn);
table.Columns.Add(taxColumn);
table.Columns.Add(totalColumn);
//
DataRow row = table.NewRow();
table.Rows.Add(row);// table
// table
DataView view = new DataView(table);
// DataGrid
dg.DataSource = view;
dg.DataBind();
#endregion
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.