
DataSet 可以理解为内存数据库,里面包括了表,而表下面有行和列。
因此,第一步要确定是哪个表,可通过索引或表名来获取。
示例如下:
LabelText = DataSet11Tables("COMMUSERS")Rows[0]["User_Name"]tostring()
LabelText = DataSet11Tables("COMMUSERS")Rows(0)Item("user_name")
LabelText=dsTables(0)Rows(i)Item( "列名 ")
LabelText=dstables[0]rows[0][ "filed "]
LabelText=dsTables[0]Rows[x][y]
可以使用OleDbConnection 来 *** 作EXCEL,当然会碰到一些缓存的问题。MicrosoftOfficeInteropExcel则没有这个顾虑。
/// <summary>
/// C#中获取Excel文件的第一个表名
/// Excel文件中第一个表名的缺省值是Sheet1$, 但有时也会被改变为其他名字 如果需要在C#中使用OleDb读写Excel文件, 就需要知道这个名字是什么 以下代码就是实现这个功能的:
/// </summary>
/// <param name="excelFileName"></param>
/// <returns></returns>
public static string GetExcelFirstTableName(string excelFileName)
{
string tableName = null;
if (FileExists(excelFileName))
{
using (OleDbConnection conn = new OleDbConnection("Provider=MicrosoftJet" +
"OLEDB40;Extended Properties=\"Excel 80\";Data Source=" + excelFileName))
{
connOpen();
DataTable dt = connGetOleDbSchemaTable(OleDbSchemaGuidTables, null);
tableName = dtRows[0][2]ToString()Trim();
}
}
return tableName;
}
string
cmdtxt2
=
"SELECT
FROM
tb_07";
SqlConnection
Con
=
new
SqlConnection(ConfigurationManagerAppSettings["ConSql"]);
ConOpen();
SqlDataAdapter
da
=
new
SqlDataAdapter(cmdtxt2,Con);
DataSet
ds
=
new
DataSet();
daFill(ds);
thisGridView1DataSource
=
ds;
thisGridView1DataBind();
拖放一个DataGrid控件
SqlConnection
conn=new
SqlConnection();
SqlDataAdapter
sda=new
SqlDataAdapter(sql语句,conn);
DataSet
ds=new
DataSet();
sdaFill(ds,表名);
thisDataGrid名称DataSourse=dstable[0]Defaultview;
可能大小写有点出入
以上就是关于如何取出dataset中的数值数据全部的内容,包括:如何取出dataset中的数值数据、各位大侠:C# 如何读取Excel的第一张表的表名、c#如何读取数据库信息等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)