对于Stata:将结果,variables和命令框分成3份感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解stata结果输出命令,并且为您提供关于.net将一个DataTable拆分成n个D
对于Stata:将结果,variables和命令框分成3份感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解stata结果输出命令,并且为您提供关于.net将一个DataTable拆分成n个DataTable、ArcEngine ITable 与System.DataTable相互转换、ASP.NET操作DataTable各种方法总结(给Datatable添加行列、DataTable选择排序等)、c# datarow [] 转换成 datatable, List
- Stata:将结果,variables和命令框分成3份(stata结果输出命令)
- .net将一个DataTable拆分成n个DataTable
- ArcEngine ITable 与System.DataTable相互转换
- ASP.NET操作DataTable各种方法总结(给Datatable添加行列、DataTable选择排序等)
- c# datarow [] 转换成 datatable, List
转 datatable
Stata:将结果,variables和命令框分成3份(stata结果输出命令)
我在Windows XP机器上使用Stata SE 11.1。 我通常更喜欢将结果,variables和命令框作为三个不同的框同时显示。 我不小心点击了合并到一个显示的东西,只让我在三个之间切换,一次只显示一个。
下面的第一张图片显示了我更喜欢看,而第二张图片显示了它目前的样子。 我怎样才能让显示器按我喜欢的方式走?
这是首选显示的图像:
在Sublime Text 3中,我可以向Stata发送一个do文件的select吗?
我需要在Windows上编译Postgresql的Stata插件?
Linux上的Stata 13:如何处理使用导出分隔的文件path中的空格?
从vim发送代码到stata
以上是首选显示器。
下面是我不再需要的当前显示。
在编辑下,进入首选项,然后加载首选项设置,然后出厂设置。 如果您的首选设置是Stata最初设置的方式,那么这将使您到达那里。 祝你好运!
.net将一个DataTable拆分成n个DataTable
/// <summary>
/// 分解数据表
/// </summary>
/// <param name="originalTab">需要分解的表</param>
/// <param name="rowsNum">每个表包含的数据量</param>
/// <returns></returns>
public DataSet SplitDataTable(DataTable originalTab, int rowsNum)
{
//获取所需创建的表数量
int tableNum = originalTab.Rows.Count / rowsNum;
//获取数据余数
int remainder = originalTab.Rows.Count % rowsNum;
DataSet ds = new DataSet();
//如果只需要创建1个表,直接将原始表存入DataSet
if (tableNum == 0)
{
ds.Tables.Add(originalTab);
}
else
{
//如果不能整除则需要+1
if (remainder!=0)
{
tableNum += 1;
}
DataTable[] tableSlice = new DataTable[tableNum];
//Save orginal columns into new table.
for (int c = 0; c<tableNum; c++)
{
tableSlice[c] = new DataTable();
foreach(DataColumn dc in originalTab.Columns)
{
tableSlice[c].Columns.Add(dc.ColumnName,dc.DataType);
}
}
//Import Rows
for (int i = 0; i<tableNum; i ++)
{
// if the current table is not the last one
if (i != tableNum -1)
{
for(int j = i * rowsNum; j< ((i+1)* rowsNum); j++)
{
tableSlice[i].ImportRow(originalTab.Rows[j]);
}
}
else
{
for(int k = i * rowsNum; k< ((i+1)* rowsNum+remainder); k++)
{
tableSlice[i].ImportRow(originalTab.Rows[k]);
}
}
}
//add all tables into a dataset
foreach(DataTable dt in tableSlice)
{
ds.Tables.Add(dt);
}
}
return ds;
}
ArcEngine ITable 与System.DataTable相互转换
/// <summary>
/// 打开dbf表
/// </summary>
/// <param name="pathName"></param>
/// <param name="tableName"></param>
/// <returns></returns>
public static ITable OpenTable(string pathName, string tableName)
{
// Create the workspace name object.
IWorkspaceName workspaceName = new WorkspaceNameClass();
workspaceName.PathName = pathName;
workspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.shapefileworkspacefactory";
// Create the table name object.
IDatasetName dataSetName = new TableNameClass();
dataSetName.Name = tableName;
dataSetName.WorkspaceName = workspaceName;
// Open the table.
IName name = (IName)dataSetName;
ITable table = (ITable)name.Open();
return table;
}
/// <summary>
/// 将ITable转换为DataTable
/// </summary>
/// <param name="mTable"></param>
/// <returns></returns>
public static DataTable ToDataTable(ITable mTable)
{
try
{
DataTable pTable = new DataTable();
for (int i = 0; i < mTable.Fields.FieldCount; i++)
pTable.Columns.Add(mTable.Fields.get_Field(i).Name);
ICursor pCursor = mTable.Search(null, false);
IRow pRrow = pCursor.NextRow();
while (pRrow != null)
{
DataRow pRow = pTable.NewRow();
string[] StrRow = new string[pRrow.Fields.FieldCount];
for (int i = 0; i < pRrow.Fields.FieldCount; i++)
StrRow[i] = pRrow.get_Value(i).ToString();
pRow.ItemArray = StrRow;
pTable.Rows.Add(pRow);
pRrow = pCursor.NextRow();
}
return pTable;
}
catch (Exception ex)
{
return null;
}
}
/// <summary>
/// 把DataTable转为ITable ,tempPath 不含文件名的问价夹路径
/// </summary>
/// <param name="mTable"></param>
/// <returns></returns>
public static ITable ToITable(DataTable mTable,string tempPath)
{
try
{
#region 新建表字段
IField pField = null;
IFields fields = new FieldsClass();
IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
fieldsEdit.FieldCount_2 = 3;
pField = new FieldClass();
IFieldEdit fieldEdit = (IFieldEdit)pField;
fieldEdit.Name_2 = "FromField";
fieldEdit.AliasName_2 = "开始字段值";
fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
fieldEdit.Editable_2 = true;
//添加开始字段
fieldsEdit.set_Field(0, pField);
IField pField1 = new FieldClass();
IFieldEdit fieldEdit1 = (IFieldEdit)pField1;
fieldEdit1.Name_2 = "ToField";
fieldEdit1.AliasName_2 = "结束字段值";
fieldEdit1.Type_2 = esriFieldType.esriFieldTypeDouble;
fieldEdit1.Editable_2 = true;
//添加结束字段
fieldsEdit.set_Field(1, pField1);
IField pField2 = new FieldClass();
IFieldEdit fieldEdit2 = (IFieldEdit)pField2;
fieldEdit2.Name_2 = "outField";
fieldEdit2.AliasName_2 = "分类字段值";
fieldEdit2.Type_2 = esriFieldType.esriFieldTypeDouble;
fieldEdit2.Editable_2 = true;
//添加重分类字段
fieldsEdit.set_Field(2, pField2);
#endregion
ShapefileWorkspaceFactoryClass class2 = new ShapefileWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace = class2.OpenFromFile(tempPath, 0);
IFeatureWorkspace pFWS = pWorkspace as IFeatureWorkspace;
//删除已有的
if (System.IO.File.Exists(tempPath + "重分类.dbf"))
System.IO.File.Delete(tempPath + "重分类.dbf");
//创建空表
ESRI.ArcGIS.Geodatabase.ITable pTable;
pTable = pFWS.CreateTable("重分类", fieldsEdit, null, null, "");
//获取表中记录数
int count=mTable .Rows .Count ;
//转换为ITable中的数据
for(int k=0;k<count ;k++)
{
//ITable 的记录
IRow row = pTable.CreateRow();
DataRow pRrow=mTable .Rows[k];
//列元素
int rowNum= pRrow .ItemArray.Length;
// 添加记录
for (int n=1;n<rowNum+1 ;n++)
{
row.set_Value(n,pRrow.ItemArray.GetValue(n-1));
row.Store ();
}
}
return pTable ;
}
catch (Exception ex)
{
return null;
}
}
/// <summary>
///保存DataTable表位DBF ,tempPath 文件完整路径
/// </summary>
/// <param name="mTable"></param>
/// <returns></returns>
public static bool SaveTable(DataTable mTable, string tempPath)
{
try
{
#region 新建表字段
IField pField = null;
IFields fields = new FieldsClass();
IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
fieldsEdit.FieldCount_2 = 3;
pField = new FieldClass();
IFieldEdit fieldEdit = (IFieldEdit)pField;
fieldEdit.Name_2 = "FromField";
fieldEdit.AliasName_2 = "开始字段值";
fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
fieldEdit.Editable_2 = true;
//添加开始字段
fieldsEdit.set_Field(0, pField);
IField pField1 = new FieldClass();
IFieldEdit fieldEdit1 = (IFieldEdit)pField1;
fieldEdit1.Name_2 = "ToField";
fieldEdit1.AliasName_2 = "结束字段值";
fieldEdit1.Type_2 = esriFieldType.esriFieldTypeDouble;
fieldEdit1.Editable_2 = true;
//添加结束字段
fieldsEdit.set_Field(1, pField1);
IField pField2 = new FieldClass();
IFieldEdit fieldEdit2 = (IFieldEdit)pField2;
fieldEdit2.Name_2 = "outField";
fieldEdit2.AliasName_2 = "分类字段值";
fieldEdit2.Type_2 = esriFieldType.esriFieldTypeDouble;
fieldEdit2.Editable_2 = true;
//添加重分类字段
fieldsEdit.set_Field(2, pField2);
#endregion
string path = System.IO.Path.GetDirectoryName(tempPath);
string fileName = System.IO.Path.GetFileName(tempPath);
ShapefileWorkspaceFactoryClass class2 = new ShapefileWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace = class2.OpenFromFile(path, 0);
IFeatureWorkspace pFWS = pWorkspace as IFeatureWorkspace;
//删除已有的
if (System.IO.File.Exists(tempPath))
System.IO.File.Delete(tempPath);
fileName = fileName.Split(''.'')[0];
//创建空表
ESRI.ArcGIS.Geodatabase.ITable pTable;
pTable = pFWS.CreateTable(fileName, fieldsEdit, null, null, "");
//获取表中记录数
int count = mTable.Rows.Count;
//转换为ITable中的数据
for (int k = 0; k < count; k++)
{
//ITable 的记录
IRow row = pTable.CreateRow();
DataRow pRrow = mTable.Rows[k];
//列元素
int rowNum = pRrow.ItemArray.Length;
// 添加记录
for (int n = 1; n < rowNum + 1; n++)
{
row.set_Value(n, pRrow.ItemArray.GetValue(n - 1));
row.Store();
}
}
return true ;
}
catch (Exception ex)
{
return false ;
}
}
ASP.NET操作DataTable各种方法总结(给Datatable添加行列、DataTable选择排序等)
本文转自:https://www.cnblogs.com/sntetwt/p/3496477.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace Gzcms.Common
{
public
class
CreateTable
{
public
static
DataTable getTable()
{
//1.创建 datatable
DataTable dt =
new
DataTable(
"datatable"
);
//可以给表创建一个名字,datatable
//2.给表加个列名:
dt.Columns.Add(
"id"
,
typeof
(System.Int32));
//类型是可以变换的,比如System.Int32,System.Double..
dt.Columns.Add(
"title"
,
typeof
(System.String));
//3.给表加行,内容:
DataRow row = dt.NewRow();
row[
"id"
] = 1;
row[
"title"
] =
"标题1"
;
dt.Rows.Add(row);
//这样就可以添加了
row = dt.NewRow();
row[
"id"
] = 2;
row[
"title"
] =
"标题2"
;
dt.Rows.Add(row);
return
dt;
/*
//4. 过滤表内容,,查找id为1的信息
DataRow[] arr = dt.Select("id=1");//返回的是一个数组
//5.将过滤的内容插入到另一个table中
DataTable dtnew = dt.Clone();//将表dt里的列信息复制到dtnew里,不是复制数据
foreach (DataRow row in arr)
{
dtnew.Rows.Add(row);//把过滤好的信息加入到dtnew里
}
dt.AcceptChanges();//添加好后,要记得刷新一下!
//6.给表排序
dt.DefaultView.Sort = "id desc";
//7.删除数据
dt.Rows.Remove(row);//根据row行信息删除
dt.Rows.RemoveAt(index);//根据index索引删除
//8.修改dt 的列信息
row2[0].BeginEdit();
row2[0]["status"] = 0;
row2[0].EndEdit();
*/
}
}
}
|
c# datarow [] 转换成 datatable, List 转 datatable
c# datarow [] 转换成 datatable, List<T> 转 datatable
DdataRow [] 转成 Datatable
private DataTable ToDataTable(DataRow[] rows)
{
if (rows == null || rows.Length == 0) return null;
DataTable tmp = rows[0].Table.Clone(); // 复制DataRow的表结构
foreach (DataRow row in rows)
{
tmp.ImportRow(row); // 将DataRow添加到DataTable中
}
return tmp;
}
List<T> 转 datatable
#region List<T> 转table
public static DataTable ListToDataTable<T>(List<T> entitys)
{
//检查实体集合不能为空
if (entitys == null || entitys.Count < 1)
{
throw new Exception("需转换的集合为空");
}
//取出第一个实体的所有Propertie
Type entityType = entitys[0].GetType();
PropertyInfo[] entityProperties = entityType.GetProperties();
//生成DataTable的structure
//生产代码中,应将生成的DataTable结构Cache起来,此处略
DataTable dt = new DataTable();
for (int i = 0; i < entityProperties.Length; i++)
{
//dt.Columns.Add(entityProperties[i].Name, entityProperties[i].PropertyType);
dt.Columns.Add(entityProperties[i].Name);
}
//将所有entity添加到DataTable中
foreach (object entity in entitys)
{
//检查所有的的实体都为同一类型
if (entity.GetType() != entityType)
{
throw new Exception("要转换的集合元素类型不一致");
}
object[] entityValues = new object[entityProperties.Length];
for (int i = 0; i < entityProperties.Length; i++)
{
entityValues[i] = entityProperties[i].GetValue(entity, null);
}
dt.Rows.Add(entityValues);
}
return dt;
}
#endregion
关于Stata:将结果,variables和命令框分成3份和stata结果输出命令的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于.net将一个DataTable拆分成n个DataTable、ArcEngine ITable 与System.DataTable相互转换、ASP.NET操作DataTable各种方法总结(给Datatable添加行列、DataTable选择排序等)、c# datarow [] 转换成 datatable, List
本文标签: