| This is for those who are already knowing a little ASP.
  This program will tranfer the data from an excel 
        file to ms access  By slightly modifying the database connectivity, 
        data can be transferred from excel to oracle.
 ===asp code starts here========== <%  On Error Resume Next' this should be always at the top like this
 '----------------------------------------------------------------------
 ' create table emp with fields 
        emp_name. make it as primary key. populate with some 
        records.
 '--------------------------------------------------------------------------------
 Set Myconn=Server.CreateObject("adodb.connection")Myconn.open "Provider=Microsoft.jet.oledb.4.0;data source=" 
        & Server.Mappath("db/emp.mdb")
 Set ObjRsACC=Server.CreateObject("adodb.recordset")
 sql="select * from emp"
 'ObjRsORA.CursorLocation=3
 ''the above line should not be there for access. 
        but needed for oracle
 ObjRsACC.open sql,myconn,2,3
 Set MyconnXL=Server.CreateObject("adodb.connection")
 MyconnXL.open "Provider=Microsoft.jet.oledb.4.0;data source=" 
        & Server.Mappath("emp.xls") & ";Extended Properties=Excel 
        8.0;"
 Set ObjRsXL=MyconnXL.Execute("select * from [emp_sheet$]")
 'First 
        row of excel should be of Field Names ' 
        The sheet name should be renamed from sheet1 to emp_sheet If ObjRsXL.eof then
 response.write("no records present in the excel worksheet")
 Else
 % >
 <table border="1">
 <tr>
 <td>
 Updation status
 </td>
 </tr>
 <tr>
 <td>
 Error Number
 </td>
 <td>
 Error Data
 </td>
 <td>
 Error source
 </td>
 </tr>
 < %
 i=1
 While Not ObjRsXL.Eof
 Err.Clear
 emp_name=ObjRsXL("emp_name")
 ObjRsACC.AddNew
 ObjRsACC("emp_name")=emp_name
 ObjRsACC.Update
 Response.write("<tr>")If Err.Number <> 0 Then
 Err.Clear
 Response.write("<td bgcolor=red> </td>")
 Response.write("<td bgcolor=red>" & Err.Number & 
        "</td>")
 Response.write("<td bgcolor=red>" & emp_name& 
        "</td>")
 Response.write("<td bgcolor=red>" & Err.Source& 
        "</td>")
 Response.write("</tr>")
 Else
 Response.write("<td>" & i & Err.Number & "</td>")
 Response.write("<td> success </td>")
 Response.write("<td colspan=2>" & emp_name& "</td>")
 Response.write("</tr>")
 i=i+1End If
 ObjRsXL.MoveNext
 Wend
 %>
 </table>
 < %
 End If
 %>
 ======code ends here==
 | 
No comments:
Post a Comment