Last time provided a method of importing from an Excel spreadsheet into a SQL Server database, provided that the EXCEL component on the machine is installed. Today, I will provide another way: don't need to install Excel, you can also import our SQL Server database. First use SQL Server's own data conversion function to import Excel into SQL Server, the table name after importing in the example below: Sheet1 $, then we will import data into our own system data sheet. . (This is the problem of data transition in 2 SQL Server tables). In short, the principle of 2 methods is to read all the data from a data source, then insert the source data into our target table by loop. The full code is as follows:
<% 'On Error Resume Next' imports Excel spreadsheet data to SQL Sever Database by Dicky 2004-12-27 16: 41: 12Function Open_CONN (SqlDatabaseEname, SqlPassword, SQLUSERNAME, SQLLOCALNAME, SQLCONN) Create a database connection object and open database connections DIM ConnStr 'SQL Server Database Connection Parameters: Database Name, User Password, User Name, Connection Name (Local Local, IP) Connstr = "Provider = SQLOLDB; User ID =" & SQLUSERNAME & "; Password =" & Sqlpassword & "; Initial Catalog =" & SqlDatabaseName & "; Data Source =" & SqlLocalName & ";" Set sqlConn = Server.CreateObject ( "ADODB.Connection") SqlConn.Open ConnStr If Err Then Err.Clear Set sqlConn = Nothing Response .Write "Data connection error!" Response.end end if End function
Function Close_conn (SQLCONN) 'Closing the Database Connection and Clears Database Connection Object If IsObject (Sqlconn) Then Sqlconn.close Set Sqlconn = Nothing End IFEND Function
Call Open_CONN ("Shat_edG", "," SA ",", "," SQLCONN) Opens the local SQL Server database connection CALL OPEN_CONN ("Shat_edg", "SA", "SSH03", SQLCONN1) ' Open Remote SQL Server Database Connections
Function Get_EMP_CnName (NTACCNT) 'obtained according to the user NT user account name Chinese Dim Sql1, Rs1 Sql1 = "Select EMP_CNAME From RF_EMPLOYEE Where EMP_NTACCNT ='" & NTACCNT & " '" Set Rs1 = Server.CreateObject ( "Adodb.RecordSet") Rs1.Open SQL1, SQLCONN1, 1, 1 IF RS1.EOF THEN GET_EMP_CNNAME = "" Else Get_Emp_cnname = RS1 ("EMP_CNAME") end if xi = nothingnd function%>