我想把上传的excel表数据导入到table5-w中,用button1_click实现,可是代码是错的,不知道怎么导入。
假如这步实现了就 用一个按键实现下面筛选的sql判断语句,用datagrid显示通过没有判断的数据。通过的就插入数据库的2个表中。可是我感觉没有参数,不知道怎么把下面的sql 语句变为存储过程
select distinct* into #t1 from Table5_w --从导入的表Table5_w中再筛选
select customer_id into #t2 from #t1 where customer_id in(select customer_id from Customer)--看customer表中有没有
insert into m_customer select customer_id ,'0505' from #t2---custoemr表中有就只插入m-customer表
select customer_id into #t3 from #t1 where customer_id in(select customer_id from LS_101...Customer t)
and customer_id not in(select customer_id from #t2) --看101中有没有
insert into m_customer select customer_id ,'0505' from #t3 ---有的话就插入m-custoemter表
--再插入customer 表中
insert into Customer select .... from #t3 c,LS_101...Customer t,sales_depot p ,channel s ,LS_SDS101...Calling m where ......
--看导不进去的有那些客户编号
select customer_id into #t5 from #t1 where customer_id not in(select customer_id from #t2)and customer_id not in(select customer_id from #t3) and customer_id
not in(select customer_id from #t4)
Public Class MultiUpload
Inherits System.Web.UI.Page
Protected WithEvents Upload As System.Web.UI.WebControls.Button
Protected WithEvents MyTitle As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents strStatus As System.Web.UI.WebControls.Label
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim cmd As SqlCommand
Dim conn As New SqlConnection(PublicModule.connstr)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyTitle.Text = "<h3>多文件上传</h3>"
Upload.Text = "开始上传"
If (Me.IsPostBack) Then Me.SaveImages()
End Sub
Private Function SaveImages() As System.Boolean
'遍历File表单元素
Dim files As System.Web.HttpFileCollection = System.Web.HttpContext.Current.Request.Files
'状态信息
Dim strMsg As New System.Text.StringBuilder("上传的文件分别是:<hr color=red>")
Dim iFile As System.Int32
Try
For iFile = 0 To files.Count - 1
'检查文件扩展名字
Dim postedFile As System.Web.HttpPostedFile = files(iFile)
Dim fileName, fileExtension As System.String
fileName = System.IO.Path.GetFileName(postedFile.FileName)
If Not (fileName = String.Empty) Then
fileExtension = System.IO.Path.GetExtension(fileName)
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>")
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>")
strMsg.Append("上传文件的文件名:" + fileName + "<br>")
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>")
'可根据扩展名字的不同保存到不同的文件夹
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName)
End If
Next
strStatus.Text = strMsg.ToString()
Return True
Catch Ex As System.Exception
strStatus.Text = Ex.Message
Return False
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connstring As String
Dim strsql As String
Dim conn As New OleDbConnection
connstring = "provider=microsoft.Jet.oledb.4.0;data source= Server.MapPath("e.xls")"
conn.ConnectionString = connstring
conn.Open()
Dim strdbname As String = "Table2"
Dim strnewfilename = Server.MapPath("+ fileName +")
Dim sql As String = "select * into" + strdbname + " from FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=" + strnewfilename + "',[Sheet1$])"
Dim cmd As OleDbCommand
cmd.Connection = conn
cmd.CommandText = sql
Try
cmd.ExecuteNonQuery()
Response.Write("恭喜 成功")
Catch err As Exception
Response.Write(err.Message)
End Try
cmd.Dispose()
conn.Close()