Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Some Problem,Please help me

Some Problem,Please help me

Scheduled Pinned Locked Moved ASP.NET
helpdatabasedata-structuressecurity
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kishore19 hotmail com
    wrote on last edited by
    #1

    My application needs Exports to Excel and From Excel to Database for that ,i have used the code For Export: Dim mySQLCommand As New SqlCommand Dim myConnection As New SqlConnection Dim datagrid1 As New DataGrid Dim DS As New DataSet Dim DT As New DataSet myConnection = New SqlConnection("Password=technologies;Persist Security Info=False;User ID=sa;Initial Catalog=Lims_Demo;Data Source=VISHWA") 'ConfigurationSettings.AppSettings("MyConStr")) myConnection.Open() Dim da As New SqlDataAdapter("SELECT top 30 ProductCode,ProductName,GenericName,RetestPeriod FROM Results where status=0", myConnection) da.Fill(DT) datagrid1.DataSource = DT datagrid1.DataBind() Response.Clear() Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Me.EnableViewState = False Dim tw As New System.IO.StringWriter Dim hw As New Html32TextWriter(tw) datagrid1.RenderControl(hw) Response.Write(tw.ToString()) Dim path As String = "C:\...\abc.doc" Response.AddHeader("content-disposition", "attachment; filename=Worddocument.xls") Response.End() 'FileStream sourceFile = new FileStream(path, FileMode.Open); 'long FileSize; 'FileSize = sourceFile.Length; 'byte[] getContent = new byte[(int)FileSize]; 'sourceFile.Read(getContent, 0, (int)sourceFile.Length); 'sourceFile.Close(); 'Response.BinaryWrite(getContent); 'dim SaveFileDialog1 as System. 'If SaveFileDialog1.ShowDialog() = DialogResult.OK Then ' RichTextBox1.SaveFile(SaveFileDialog1.FileName, _ ' RichTextBoxStreamType.PlainText) 'End If myConnection.Close() the above coding is working very good and giving the required results but when i am going to Import Excel data to Database I have used the code, which i found in Msdn help '---------------------Importing Data From Excel to Database If Not FILE1.PostedFile.FileName = "" Then FilePath = FILE1.PostedFile.FileName End If 'Excel Work Sheet Database Connection MyConnection = New System.Data.OleDb.OleDbConnection( _ "provider=Microsoft.Jet.OLEDB.4.0; " & _ "data source=" & FilePath & "; " & _ "Extended Properties=Excel 8.0;") 'Select the data from Sheet1 of the workbook. 'MyConnection.Open() 'Dim dt As Table = MyConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null) Dim f As Array f = Split(FilePath, "\") Dim k As Integer = f.Length Dim str As String = f(k - 1) Dim filename As String = str.Substring(0, str.LastIndexOf(".")) 'str.Split(".xls") 'Dim f1 As Array 'f1 = Split(str, ".") 'Dim str1 As String = f1(f1.Length - 1) Try D

    _ 1 Reply Last reply
    0
    • K kishore19 hotmail com

      My application needs Exports to Excel and From Excel to Database for that ,i have used the code For Export: Dim mySQLCommand As New SqlCommand Dim myConnection As New SqlConnection Dim datagrid1 As New DataGrid Dim DS As New DataSet Dim DT As New DataSet myConnection = New SqlConnection("Password=technologies;Persist Security Info=False;User ID=sa;Initial Catalog=Lims_Demo;Data Source=VISHWA") 'ConfigurationSettings.AppSettings("MyConStr")) myConnection.Open() Dim da As New SqlDataAdapter("SELECT top 30 ProductCode,ProductName,GenericName,RetestPeriod FROM Results where status=0", myConnection) da.Fill(DT) datagrid1.DataSource = DT datagrid1.DataBind() Response.Clear() Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Me.EnableViewState = False Dim tw As New System.IO.StringWriter Dim hw As New Html32TextWriter(tw) datagrid1.RenderControl(hw) Response.Write(tw.ToString()) Dim path As String = "C:\...\abc.doc" Response.AddHeader("content-disposition", "attachment; filename=Worddocument.xls") Response.End() 'FileStream sourceFile = new FileStream(path, FileMode.Open); 'long FileSize; 'FileSize = sourceFile.Length; 'byte[] getContent = new byte[(int)FileSize]; 'sourceFile.Read(getContent, 0, (int)sourceFile.Length); 'sourceFile.Close(); 'Response.BinaryWrite(getContent); 'dim SaveFileDialog1 as System. 'If SaveFileDialog1.ShowDialog() = DialogResult.OK Then ' RichTextBox1.SaveFile(SaveFileDialog1.FileName, _ ' RichTextBoxStreamType.PlainText) 'End If myConnection.Close() the above coding is working very good and giving the required results but when i am going to Import Excel data to Database I have used the code, which i found in Msdn help '---------------------Importing Data From Excel to Database If Not FILE1.PostedFile.FileName = "" Then FilePath = FILE1.PostedFile.FileName End If 'Excel Work Sheet Database Connection MyConnection = New System.Data.OleDb.OleDbConnection( _ "provider=Microsoft.Jet.OLEDB.4.0; " & _ "data source=" & FilePath & "; " & _ "Extended Properties=Excel 8.0;") 'Select the data from Sheet1 of the workbook. 'MyConnection.Open() 'Dim dt As Table = MyConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null) Dim f As Array f = Split(FilePath, "\") Dim k As Integer = f.Length Dim str As String = f(k - 1) Dim filename As String = str.Substring(0, str.LastIndexOf(".")) 'str.Split(".xls") 'Dim f1 As Array 'f1 = Split(str, ".") 'Dim str1 As String = f1(f1.Length - 1) Try D

      _ Offline
      _ Offline
      _AK_
      wrote on last edited by
      #2

      After you export the data to the excel file close it and then try to export the data from excel to database.

      Best Regards, Apurva Kaushal

      K 1 Reply Last reply
      0
      • _ _AK_

        After you export the data to the excel file close it and then try to export the data from excel to database.

        Best Regards, Apurva Kaushal

        K Offline
        K Offline
        kishore19 hotmail com
        wrote on last edited by
        #3

        Thanks Apurv but Even Iam doing same thing what u said, it is giving same error kishore

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups