前提:有数据库db
其中有数据表student(包括:姓名,性别代码)
xb(包括:性别代码,性别)
已有的Excel数据表“excel1”内容包括:姓名 性别
实现功能:点击“导入”按钮,打开窗口选择excel1表,dataSet中显示数据谢谢大家,帮忙解决一下
其中有数据表student(包括:姓名,性别代码)
xb(包括:性别代码,性别)
已有的Excel数据表“excel1”内容包括:姓名 性别
实现功能:点击“导入”按钮,打开窗口选择excel1表,dataSet中显示数据谢谢大家,帮忙解决一下
解决方案 »
- win 2008 server获取mac地址的问题
- 如何将拖到容器控件上的控件的父对象设置为容器控件中的子控件
- while(buffter=="")""指的是什么??
- 请教关于System.Drawing.Point类型的坐标对该如何存储到一个集合中的问题
- 在窗体中绘制一个图,如何让它一直显示着??
- 用GetWebPage(string uri, string method, string encode)采集www.sohu.com乱码问题
- 界面上按钮的位置大小如何随着FORM大小的改变而改变
- Can't find KeyCodeV2.dll or invalid KeyCode問題該怎么解決
- 调用线程无法访问此对象,因为另一个线程拥有该对象。
- 大虾,请指教!
- 如何根据关键列字段动态改变DataGridViewCOMBOX列的绑定选项?
- 有关dropdownlist赋值问题
{
string reFileName=this.openFileDialog1.FileName;
try
{
GetPath();
OleDbConnection ExcelConn=new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source="+reFileName+";Extended Properties=Excel 8.0;");
ExcelConn.Open();
sda.SelectCommand=new OleDbCommand("select * from [Sheet1$]",ExcelConn);
sda.Fill(ds,"CurrentTable");
this.dataGrid1.DataSource=ds.Tables["CurrentTable"].DefaultView;
ExcelConn.Close();
ExcelConn.Dispose();
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
}
public DataSet ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Path + ";" +
"Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcelPSID = "";
string strExcelBox = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcelPSID="select * from [Sheet1$]"; //Excel表Sheet1
myCommand = new OleDbDataAdapter(strExcelPSID, strConn);
ds = new DataSet();
myCommand.Fill(ds,"Sheet1");
strExcelBox="select * from [Sheet2$]"; //Excel表Sheet1
myCommand = new OleDbDataAdapter(strExcelBox, strConn);
conn.Close();
myCommand.Fill(ds,"Sheet2");
return ds;
}
返回DataSet,可以DataGrid绑定或直接导入到Sql数据库
建議導入方法:調用DTS方式導入,又快又方便。
DataSet是??