Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 25th, 2007, 08:39 AM
Authorized User
 
Join Date: Oct 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default Import & Export Excel File

Hi Frnds,

         I have got so many solutions from this forum. I need another help from you people.

         Can you give me some code by which I can import/export an excel file to/from MS SQL Server 2000?? I am using ASP.NET1.1(VB).

Thanks in advance....

 
Old January 25th, 2007, 04:47 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

'To export
    Sub exportInventory(ByVal s As Object, ByVal e As ImageClickEventArgs) Handles btnInventory.Click
        _oConn.Open()
        Dim Client As New Client(_oConn, _ClientID)
        Dim Facility As New Facility(_oConn, _FacID)
        Dim Rule As New Rule(_oConn, _RuleID)
        Response.Clear()
        grdInventoryExport.Visible = True
        Dim SQL As String = ""
        Dim oDA As New SqlDataAdapter(SQL, _oConn)
        Dim oDS As New DataSet
        oDA.Fill(oDS)

        grdInventoryExport.DataSource = oDS
        grdInventoryExport.DataBind()
        Response.Clear()
        Response.AddHeader("content-disposition", "attachment;filename=" & Facility.Facility & "_" & Rule.RuleNumber & "_Inventory_" & Year(txtInvDate.Text) & Right("0" & Month(txtInvDate.Text), 2) & Right("0" & Day(txtInvDate.Text), 2) & ".xls")
        Response.Charset = ""
        Response.Cache.SetCacheability(HttpCacheability.Pu blic)
        Response.ContentType = "application/vnd.xls"
        Dim StringWrite As New System.IO.StringWriter
        Dim HtmlTextWriter As New HtmlTextWriter(StringWrite)
        grdInventoryExport.RenderControl(HtmlTextWriter)
        Response.Write(StringWrite.ToString())
        grdInventoryExport.Visible = False
        _oConn.Close()
        Response.End()
    End Sub

'To Import
I convert my Excel documents to tab delimited .txt files. Importing the Excel files just got too messy for me.
Here's a snippet for importing .txt files. Should get you started.
                _xConn.Open()
                If txtInvFile.PostedFile.ContentLength = 0 Or Right(txtInvFile.PostedFile.FileName, 4) <> ".txt" Then
                    Throw New Exception("Please provide a valid tab-delimited .txt file")
                ElseIf Not CheckDate(txtInvDate.Text) Then
                    Throw New Exception("Please provide a valid date")
                ElseIf chkSave.Checked = False And InvCount(ddlFacID.SelectedValue, ddlRuleID.SelectedValue) > 0 Then
                    Throw New Exception("An inventory already exists for this facility")
                End If
                'Upload File
                txtInvFile.PostedFile.SaveAs(Application("fsoMyAva nti") & "public\" & txtInvFile.PostedFile.FileName.Substring(txtInvFil e.PostedFile.FileName.LastIndexOf("\") + 1))
                File = txtInvFile.PostedFile.FileName.Substring(txtInvFil e.PostedFile.FileName.LastIndexOf("\") + 1)
                SetAttributes(Application("fsoMyAvanti") & "public\" & File, Temporary)
                'Create Temporary Table
                Dim Data As StreamReader = OpenText(Application("fsoMyAvanti") & "public\" & File)
                Dim Rows As Array
                Dim Cols As String
                Rows = Split(Data.ReadToEnd(), vbCrLf)
                Cols = Replace(Rows(0), vbTab, " varchar(100), ") & " varchar(100)"
                Data.Close()
                Dim CMD0 As New SqlCommand("CREATE TABLE [InventoryImport] (" & Cols & ") ON [PRIMARY]; BULK INSERT InventoryImport FROM '" & Application("fsoMyAvanti") & "public\" & File & "' WITH (FIRSTROW = 2, FIELDTERMINATOR = '\t', ROWTERMINATOR = '\n');", _oConn)
                CMD0.ExecuteNonQuery()



 
Old March 5th, 2007, 09:16 AM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi
 how to export excel sheet data in to sql server using C # code in ASP.net 1.1,i need it urgently. plz help.

 
Old March 5th, 2007, 09:22 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Read Rich's post above, as his method to import data should give you a good jumping off point on how to do this.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 5th, 2007, 09:24 AM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi
can u send me codes for exporting excel file to sql table in c# for asp.net 1.0,, i need it urgently..
 secondly from the excel sheet data has to be stored in to sql table and before that each data need to validated. can u tell me how to gp for it progaramtically . ut will be more helpful if u can provide sample code..


 
Old March 5th, 2007, 09:28 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Quote:
quote:Originally posted by rstelma
'To Import
I convert my Excel documents to tab delimited .txt files. Importing the Excel files just got too messy for me.
Here's a snippet for importing .txt files. Should get you started.
                _xConn.Open()
                If txtInvFile.PostedFile.ContentLength = 0 Or Right(txtInvFile.PostedFile.FileName, 4) <> ".txt" Then
                    Throw New Exception("Please provide a valid tab-delimited .txt file")
                ElseIf Not CheckDate(txtInvDate.Text) Then
                    Throw New Exception("Please provide a valid date")
                ElseIf chkSave.Checked = False And InvCount(ddlFacID.SelectedValue, ddlRuleID.SelectedValue) > 0 Then
                    Throw New Exception("An inventory already exists for this facility")
                End If
                'Upload File
                txtInvFile.PostedFile.SaveAs(Application("fsoMyAva nti") & "public\" & txtInvFile.PostedFile.FileName.Substring(txtInvFil e.PostedFile.FileName.LastIndexOf("\") + 1))
                File = txtInvFile.PostedFile.FileName.Substring(txtInvFil e.PostedFile.FileName.LastIndexOf("\") + 1)
                SetAttributes(Application("fsoMyAvanti") & "public\" & File, Temporary)
                'Create Temporary Table
                Dim Data As StreamReader = OpenText(Application("fsoMyAvanti") & "public\" & File)
                Dim Rows As Array
                Dim Cols As String
                Rows = Split(Data.ReadToEnd(), vbCrLf)
                Cols = Replace(Rows(0), vbTab, " varchar(100), ") & " varchar(100)"
                Data.Close()
                Dim CMD0 As New SqlCommand("CREATE TABLE [InventoryImport] (" & Cols & ") ON [PRIMARY]; BULK INSERT InventoryImport FROM '" & Application("fsoMyAvanti") & "public\" & File & "' WITH (FIRSTROW = 2, FIELDTERMINATOR = '\t', ROWTERMINATOR = '\n');", _oConn)
                CMD0.ExecuteNonQuery()
As I said, this should be a good jumping off point for you to get started.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Export then Import problem courtney_ctisn Classic ASP Basics 8 October 18th, 2007 09:57 AM
How to import & export beetle_jaipur SQL Server 2005 0 September 16th, 2006 04:17 AM
Export Data to Excel & Generate Graphs vinod_pawar1 ASP.NET 1.0 and 1.1 Professional 3 July 15th, 2006 01:03 AM
import & export data script minhpx SQL Language 1 January 4th, 2005 01:15 AM
Import an excel file into access arjunvs Access VBA 1 September 15th, 2004 07:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.