Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 25th, 2007, 08:39 AM
Authorized User
 
Join Date: Oct 2006
Location: Kolkata, West Bengal, India.
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....

  #2 (permalink)  
Old January 25th, 2007, 04:47 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
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()



  #3 (permalink)  
Old March 5th, 2007, 09:16 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
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.

  #4 (permalink)  
Old March 5th, 2007, 09:22 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
  #5 (permalink)  
Old March 5th, 2007, 09:24 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
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..


  #6 (permalink)  
Old March 5th, 2007, 09:28 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:34 PM.


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