public void btn_DuQu_Click(object sender,System.EventArgs e)
{//读取excel
if(this.Up_DuQu.Value!="")
{
string sPath=this.Up_DuQu.Value.ToString().Trim();
string connStr ="Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ sPath +";Extended Properties='Excel 8.0;IMEX=1'";
string sqlStr="select * from [Sheet1$]";
OleDbConnection myConn=new OleDbConnection(connStr);
myConn.Open();
OleDbCommand myCmd=new OleDbCommand(sqlStr,myConn);
OleDbDataAdapter myda=new OleDbDataAdapter(myCmd);
DataSet myDs=new DataSet();
myda.Fill(myDs,"userinfo");
DG_DaoRu.DataSource=myDs;
DG_DaoRu.DataBind();
if(myDs.Tables[0].Rows.Count> 0)
{ //excel的索引从0开始
string sSql= "";
string CnnString="Provider=SQLOLEDB;database=WeiQuan;server=(local);uid=sa;pwd=admin";
OleDbConnection conn = new
OleDbConnection(CnnString);
conn.Open
();
for(int i=0; i<myDs.Tables[0].Rows.Count; i++)
{
//ZuoPinClass_ID Site_Name Site_URL Site_IP Site_IP_City LinkDesc LinkSourc PlatForm Site_City Site_ICP Site_WLink_Man Site_WLink_Tel Site_WLink_MTel Site_WLink_Email Site_WLink_QQ Site_WLink_MSN Site_WLink_CZ Site_Link_Man Site_Link_Tel
Site_Link_Email Site_Link_QQ Site_Link_MSN Site_Link_CZ Site_Abstract
string sSite_Contact=myDs.Tables[0].Rows[i].ItemArray[14].ToString();//电话、Email、传真(WQ_Main)
string[] sitetel=sSite_Contact.Split('$');
string site0=sitetel[0];
string site1=sitetel[1];
string site2=sitetel[2];
string site3=sitetel[3];
string site4=sitetel[4];
string site5=sitetel[5];
sSql="insert into WQ_Main(ZuoPinClass_ID,Site_Name,Site_URL,Site_IP,Site_IP_City,LinkDesc,LinkSourc,PlatForm,Site_City,Site_ICP,Site_Link_Man,Site_Link_Tel,Site_Link_Email,Site_Link_QQ,Site_Link_MSN,Site_Link_CZ,Site_Abstract) values ('15', '"+myDs.Tables[0].Rows[i].ItemArray[2].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[3].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[4].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[5].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[6].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[7].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[8].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[9].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[13].ToString()+"','"+site0+"','"+site1+"','"+site2+"','"+site3+"','"+site4+"','"+site5+"','"+myDs.Tables[0].Rows[i].ItemArray[16].ToString()+"');insert into WQ_FuDong(ZuoPinClass_ID,Site_Name,Site_URL,Qin_URL) values ('15', '"+myDs.Tables[0].Rows[i].ItemArray[2].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[3].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[27].ToString()+"')";
//浮动 sSql="insert into WQ_FuDong(ZuoPinClass_ID,Site_Name,Site_URL,Qin_URL) values ('"+myDs.Tables[0].Rows[i].ItemArray[1].ToString()+"', '"+myDs.Tables[0].Rows[i].ItemArray[2].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[3].ToString()+"','"+myDs.Tables[0].Rows[i].ItemArray[27].ToString()+"')";
try
{
OleDbCommand my_Cmd=new
OleDbCommand(sSql,conn);
my_Cmd.ExecuteNonQuery();
lbl_msg.Text = "数据导入成功!!";
}
catch
{
lbl_msg.Text ="数据导入失败";
}
}
conn.Close();
}
else
{
this.lbl_msg.Text="请选择EXCEL文件!!!";
return;
}
}
}