using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
string path = System.IO.Path.GetFullPath(this.FileUpload1.PostedFile.FileName);
string conn = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =" + path + ";Extended Properties=Excel 8.0";
//"Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source=" + Server.MapPath("../ExcelData.xls") + ";" + "Extended Properties=Excel 8.0;"
OleDbConnection thisconnection = new OleDbConnection(conn);
thisconnection.Open();
string Sql = "select * from [Sheet1$]";
OleDbDataAdapter mycommand = new OleDbDataAdapter(Sql, thisconnection);
DataSet ds = new DataSet();
mycommand.Fill(ds);
int x = ds.Tables[0].Rows.Count;
string xx = ds.Tables[0].Rows[1][0].ToString();
SqlConnection thisconnection1 = new SqlConnection("server=192.168.0.250;database=sms_mjn;uid=111;pwd=1111");
thisconnection1.Open();
int count = ds.Tables[0].Rows.Count;
for (int j = 0; j < count; j++)
{
string id_1;
id_1 = ds.Tables[0].Rows[j][0].ToString();
string id_2 = ds.Tables[0].Rows[j][1].ToString();
string id_3 = ds.Tables[0].Rows[j][2].ToString();
string excelsql = "insert into sendto (phone,msg,status0)values('" + id_1 + "','" + id_2 + "','" + id_3 + "')";
SqlCommand mycommand1 = new SqlCommand(excelsql, thisconnection1);
mycommand1.ExecuteNonQuery();
}
thisconnection1.Close();
thisconnection.Close();
Response.Write("<script>alert('添加成功!');</script>");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}