....................
private void Button1_Click(object sender, System.EventArgs e)
{
string strFilePath=File1.PostedFile.FileName ;
string strSheetNamee="sheet1";
DataGrid1.DataSource =ExcelToDS(strFilePath,strSheetNamee).Tables[0].DefaultView ;
DataGrid1.DataBind ();
} public DataSet ExcelToDS(string filePath,string sheetName)
{
string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+filePath+";Extended Properties=Excel 8.0;";
OleDbConnection myConn=new OleDbConnection(strConn);
OleDbDataAdapter myDa=new OleDbDataAdapter("select * from ["+sheetName+"$]",myConn);
DataSet ds=new DataSet();
myDa.Fill(ds) ;
return ds;
}
................................
1.
name sex add
Name1 Male Add1
Name2 Male add2
Name3 male add3
//这样的数据时是对的
2.
a b c e
a b c d
a b c d
d d d d
//这样也对3.
1 2 3 4
2 2 3 3
3 3 3 3
4 4 4 4
//这时竟F1 F2 F3 F4
2 2 3 3
3 3 3 3
4 4 4 4
4.
a b c d
1 2 3 4
b c d e
a a a a
1 1 1 1
6 6 6 6
//这个更不对了 竟成了 a b c d
1 2 3 4
1 1 1 1
6 6 6 6 !!!!!!!!!!!!郁闷啊...为什么会这样啊-_-,有什么办法能解决吗(在不改变数据表的情况下数字前加个'是可以解决但那不是想要的)-_-,
好心人们帮帮忙啊
private void Button1_Click(object sender, System.EventArgs e)
{
string strFilePath=File1.PostedFile.FileName ;
string strSheetNamee="sheet1";
DataGrid1.DataSource =ExcelToDS(strFilePath,strSheetNamee).Tables[0].DefaultView ;
DataGrid1.DataBind ();
} public DataSet ExcelToDS(string filePath,string sheetName)
{
string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+filePath+";Extended Properties=Excel 8.0;";
OleDbConnection myConn=new OleDbConnection(strConn);
OleDbDataAdapter myDa=new OleDbDataAdapter("select * from ["+sheetName+"$]",myConn);
DataSet ds=new DataSet();
myDa.Fill(ds) ;
return ds;
}
................................
1.
name sex add
Name1 Male Add1
Name2 Male add2
Name3 male add3
//这样的数据时是对的
2.
a b c e
a b c d
a b c d
d d d d
//这样也对3.
1 2 3 4
2 2 3 3
3 3 3 3
4 4 4 4
//这时竟F1 F2 F3 F4
2 2 3 3
3 3 3 3
4 4 4 4
4.
a b c d
1 2 3 4
b c d e
a a a a
1 1 1 1
6 6 6 6
//这个更不对了 竟成了 a b c d
1 2 3 4
1 1 1 1
6 6 6 6 !!!!!!!!!!!!郁闷啊...为什么会这样啊-_-,有什么办法能解决吗(在不改变数据表的情况下数字前加个'是可以解决但那不是想要的)-_-,
好心人们帮帮忙啊
解决方案 »
- C#创建位图图像
- 棋盘覆盖 一个格子输出有问题
- 求教:一按TAB键就弹出当前控件的NAME和TABINDEX
- 向有经验的大哥大姐们学习,请当误你们2分钟的时候,来帮帮小弟!!!!
- c#调用0cx问题
- 刚学C#,问一个很菜得问题
- .NET源码调试的时候 总是进入f:\dd\ndp\clr\src\这个目录查找,如何改变目录
- 关于一个释放的问题,我传递的是个引用参数,然后释放了,请问那个外面也释放了吗
- 有关数据库->dateset->XML->dateset->数据库的问题
- C#获取时间的一个问题
- 求助Visual Studio 2005(winform) TextBox输入数字
- 实现限定文本框只能输入数字?以下代码有误?
---
我自己解决了..好心人有好报..分给了..