各位有没有示例提供一下?谢谢!
我的想法是,DataSet以xml存,xml其实也是文本,为什么就是不能直接转换?
各位高人指导一下,不胜感激!
6 个解决方案
#1
请参考:
演练:将 XML 数据读入数据集
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vbcon/html/vbwlkWalkthroughAccessingXMLData.asp
演练:将 XML 数据读入数据集
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vbcon/html/vbwlkWalkthroughAccessingXMLData.asp
#2
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("column1",string));
DataSet ds = new DataSet();
ds.Tables.Add(table);
DataRow row = ds.Tables[0].NewRow();
row["column1"] = "...";//你的文本文件的内容。
ds.Tables[0].Rows.Add(row);
table.Columns.Add(new DataColumn("column1",string));
DataSet ds = new DataSet();
ds.Tables.Add(table);
DataRow row = ds.Tables[0].NewRow();
row["column1"] = "...";//你的文本文件的内容。
ds.Tables[0].Rows.Add(row);
#3
同意楼上的……
#4
如果文本文件符合XML格式就用dataset.readxlm(试一试),如果是符合数据格式的,可以用ADO控件试试。
#5
给你点实际的东东:
/// <summary>
/// 将文本文件内容(.txt)数据转换成DataView
/// </summary>
/// <param name="ExcelPath"></param>
/// <returns></returns>
public DataView ProjValidateDateMove(string txtPath)
{
//更改文本文件内容
ModifyTxt(txtPath);
//把文本文件写入DataSet
string ConnectionString;
string SQLString;
ConnectionString = @ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+System.IO.Path.GetDirectoryName(txtPath) + ";Extended Properties=\"TEXT;HDR=no;FMT=Delimited\"";
SQLString = " Select * From "+System.IO.Path.GetFileName(txtPath) ;
System.Data.OleDb.OleDbConnection ConnectionText = new System.Data.OleDb.OleDbConnection();
ConnectionText.ConnectionString = ConnectionString;
ConnectionText.Open();
System.Data.OleDb.OleDbDataAdapter AdapterText = new System.Data.OleDb.OleDbDataAdapter(SQLString, ConnectionText);
DataSet DataSetText=new DataSet();
AdapterText.Fill(DataSetText, "TextFile");
dsEnterpriseValidate dsNew=new dsEnterpriseValidate();
int iCount=DataSetText.Tables["TextFile"].Rows.Count;
string sTemp;
for(int i=0;i<iCount;i++)
{
if(i==0) continue; //从第二行开始写数据
sTemp=DataSetText.Tables["TextFile"].Rows[i][0].ToString();
if (sTemp.Trim()!="")
{
AddRow(sTemp,ref dsNew);
}
}
return dsNew.Tables["EnterpriseValidate"].DefaultView;
}
/// <summary>
/// 将文本文件内容(.txt)数据转换成DataView
/// </summary>
/// <param name="ExcelPath"></param>
/// <returns></returns>
public DataView ProjValidateDateMove(string txtPath)
{
//更改文本文件内容
ModifyTxt(txtPath);
//把文本文件写入DataSet
string ConnectionString;
string SQLString;
ConnectionString = @ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+System.IO.Path.GetDirectoryName(txtPath) + ";Extended Properties=\"TEXT;HDR=no;FMT=Delimited\"";
SQLString = " Select * From "+System.IO.Path.GetFileName(txtPath) ;
System.Data.OleDb.OleDbConnection ConnectionText = new System.Data.OleDb.OleDbConnection();
ConnectionText.ConnectionString = ConnectionString;
ConnectionText.Open();
System.Data.OleDb.OleDbDataAdapter AdapterText = new System.Data.OleDb.OleDbDataAdapter(SQLString, ConnectionText);
DataSet DataSetText=new DataSet();
AdapterText.Fill(DataSetText, "TextFile");
dsEnterpriseValidate dsNew=new dsEnterpriseValidate();
int iCount=DataSetText.Tables["TextFile"].Rows.Count;
string sTemp;
for(int i=0;i<iCount;i++)
{
if(i==0) continue; //从第二行开始写数据
sTemp=DataSetText.Tables["TextFile"].Rows[i][0].ToString();
if (sTemp.Trim()!="")
{
AddRow(sTemp,ref dsNew);
}
}
return dsNew.Tables["EnterpriseValidate"].DefaultView;
}
#6
哇,这么久了,才有人回应,晕死!结贴
#1
请参考:
演练:将 XML 数据读入数据集
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vbcon/html/vbwlkWalkthroughAccessingXMLData.asp
演练:将 XML 数据读入数据集
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vbcon/html/vbwlkWalkthroughAccessingXMLData.asp
#2
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("column1",string));
DataSet ds = new DataSet();
ds.Tables.Add(table);
DataRow row = ds.Tables[0].NewRow();
row["column1"] = "...";//你的文本文件的内容。
ds.Tables[0].Rows.Add(row);
table.Columns.Add(new DataColumn("column1",string));
DataSet ds = new DataSet();
ds.Tables.Add(table);
DataRow row = ds.Tables[0].NewRow();
row["column1"] = "...";//你的文本文件的内容。
ds.Tables[0].Rows.Add(row);
#3
同意楼上的……
#4
如果文本文件符合XML格式就用dataset.readxlm(试一试),如果是符合数据格式的,可以用ADO控件试试。
#5
给你点实际的东东:
/// <summary>
/// 将文本文件内容(.txt)数据转换成DataView
/// </summary>
/// <param name="ExcelPath"></param>
/// <returns></returns>
public DataView ProjValidateDateMove(string txtPath)
{
//更改文本文件内容
ModifyTxt(txtPath);
//把文本文件写入DataSet
string ConnectionString;
string SQLString;
ConnectionString = @ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+System.IO.Path.GetDirectoryName(txtPath) + ";Extended Properties=\"TEXT;HDR=no;FMT=Delimited\"";
SQLString = " Select * From "+System.IO.Path.GetFileName(txtPath) ;
System.Data.OleDb.OleDbConnection ConnectionText = new System.Data.OleDb.OleDbConnection();
ConnectionText.ConnectionString = ConnectionString;
ConnectionText.Open();
System.Data.OleDb.OleDbDataAdapter AdapterText = new System.Data.OleDb.OleDbDataAdapter(SQLString, ConnectionText);
DataSet DataSetText=new DataSet();
AdapterText.Fill(DataSetText, "TextFile");
dsEnterpriseValidate dsNew=new dsEnterpriseValidate();
int iCount=DataSetText.Tables["TextFile"].Rows.Count;
string sTemp;
for(int i=0;i<iCount;i++)
{
if(i==0) continue; //从第二行开始写数据
sTemp=DataSetText.Tables["TextFile"].Rows[i][0].ToString();
if (sTemp.Trim()!="")
{
AddRow(sTemp,ref dsNew);
}
}
return dsNew.Tables["EnterpriseValidate"].DefaultView;
}
/// <summary>
/// 将文本文件内容(.txt)数据转换成DataView
/// </summary>
/// <param name="ExcelPath"></param>
/// <returns></returns>
public DataView ProjValidateDateMove(string txtPath)
{
//更改文本文件内容
ModifyTxt(txtPath);
//把文本文件写入DataSet
string ConnectionString;
string SQLString;
ConnectionString = @ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+System.IO.Path.GetDirectoryName(txtPath) + ";Extended Properties=\"TEXT;HDR=no;FMT=Delimited\"";
SQLString = " Select * From "+System.IO.Path.GetFileName(txtPath) ;
System.Data.OleDb.OleDbConnection ConnectionText = new System.Data.OleDb.OleDbConnection();
ConnectionText.ConnectionString = ConnectionString;
ConnectionText.Open();
System.Data.OleDb.OleDbDataAdapter AdapterText = new System.Data.OleDb.OleDbDataAdapter(SQLString, ConnectionText);
DataSet DataSetText=new DataSet();
AdapterText.Fill(DataSetText, "TextFile");
dsEnterpriseValidate dsNew=new dsEnterpriseValidate();
int iCount=DataSetText.Tables["TextFile"].Rows.Count;
string sTemp;
for(int i=0;i<iCount;i++)
{
if(i==0) continue; //从第二行开始写数据
sTemp=DataSetText.Tables["TextFile"].Rows[i][0].ToString();
if (sTemp.Trim()!="")
{
AddRow(sTemp,ref dsNew);
}
}
return dsNew.Tables["EnterpriseValidate"].DefaultView;
}
#6
哇,这么久了,才有人回应,晕死!结贴