日期:2014-05-18  浏览次数:20416 次

两张Excel导入GirdView
今天要实现一张报表。
本人的想法是两张Excel表先导入一个GirdView中,然后再导入数据库里。
期间GirdView里的数据需要做一些变动,才导入数据库。

本人今天参考了清清月儿的例子,http://blog.csdn.net/21aspnet/archive/2007/03/25/1540301.aspx
先简单导入一张excel表试一下,可惜出师不利。
错误指向myda.Fill(myds);
它报External   table   is   not   in   the   expected   format.错误。

help   me     !

------解决方案--------------------
先把excel读取到dataset进行操作,你把你读取到excel的代码贴出来!!!
------解决方案--------------------
Excel 直接就可以导入数据库中 还用中间转一下啊
------解决方案--------------------
// 导入XLS到数据库
private void btnConvert_Click(object sender, EventArgs e)
{
if (btnStart.Text.Equals(Complete, StringComparison.OrdinalIgnoreCase))
{
this.Dispose();
return;
}

if (tbXlsTableName.Text.Length == 0)
{
MessageBox.Show(ResourceFactory.GetMultilanguage( "EXCELSHEETNAME ") +
ResourceFactory.GetMultilanguage( "CANNOTBLANK "));
return;
}

progressBar1.Value = 0;
string oleDbConnectionString = string.Format( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0};Extended Properties=Excel 8.0; ",
lblFileName.Text);
DataTable xlsTable = new DataTable();
OleDbConnection xlsConnection = new OleDbConnection(oleDbConnectionString);

string sqlConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings[1].ConnectionString;
SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);

// True: 导入OPC
if (comboBoxDataTable.SelectedItem.ToString().Equals( "OPC ", StringComparison.OrdinalIgnoreCase))
{
if (MessageBox.Show(ResourceFactory.GetMultilanguage( "CONFIRMOPCID "), string.Empty, MessageBoxButtons.OKCancel) == DialogResult.OK)
{
columns = new string[] { "TagName ", "OpcId ", "ItemId " };
columnsName = OpcItemIdColumnsName;
tableName = "TOpcItemId ";

ImportOpc(xlsConnection, sqlConnection);
}
}
else // 导入Tag
{
columns = new string[] { "TagName ", "ScanMode ", "MessageCHS ", "MessageCHT ", "Severity ", "Solution ", "AreaID " };
columnsName = AlarmTagColumnsName;
tableName = "TAlarmTag ";

ImportTag(xlsConnection, sqlConnection);
}
}
------解决方案--------------------
public DataSet ExcelToDS()
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source= " + this.textBox1.Text + "; " + "Extended Properties=Excel 8.0; ";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = " ";
OleDbDataAdapter myCommand = null;
strExcel = "select * from [Sheet$] ";
myCommand = new OleDbDataAdapter(strExcel, strConn);
DataSet ds = new DataSet();