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. General Programming
  3. Visual Basic
  4. regarding excel sheet

regarding excel sheet

Scheduled Pinned Locked Moved Visual Basic
sysadminhelptutorial
2 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.
  • N Offline
    N Offline
    nagalakshmibasireddy
    wrote on last edited by
    #1

    hello, The code shown below is for excel sheet generation but when i execute this i am getting an error as access is denied .plz go though the code and if any mistake plz correct it .... Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click da1.MissingSchemaAction = MissingSchemaAction.AddWithKey CMD.Connection = con con.Open() CMD.CommandType = CommandType.StoredProcedure CMD.CommandText = "ACE_CONTROLTOWER" Dim cellid As New SqlParameter Dim fromDATE As New SqlParameter 'Dim tomonth As New SqlParameter 'Dim fromyear As New SqlParameter Dim toDATE As New SqlParameter cellid.ParameterName = "@CELLID" cellid.SqlDbType = SqlDbType.VarChar cellid.Value = TextBox1.Text cellid.Direction = ParameterDirection.Input CMD.Parameters.Add(cellid) fromDATE.ParameterName = "@fromDATE" fromDATE.SqlDbType = SqlDbType.DateTime fromDATE.Value = TextBox2.Text fromDATE.Direction = ParameterDirection.Input CMD.Parameters.Add(fromDATE) toDATE.ParameterName = "@toDATE" toDATE.SqlDbType = SqlDbType.DateTime toDATE.Value = TextBox5.Text toDATE.Direction = ParameterDirection.Input CMD.Parameters.Add(toDATE) Dim dr As SqlDataReader dr = CMD.ExecuteReader() DataGrid2.DataSource = dr DataGrid2.DataBind() dr.Close() 'closing data reader CMD.Dispose() con.Close() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click bln = CreateExcelWorkbook("example") '= Server.MapPath(".") + "\PWReports\" filePath = "c:\" filename = "example" filePath = filePath & filename & ".xls" Dim MyFileStream As FileStream = New FileStream(filePath, FileMode.Open) Dim FileSize As Long FileSize = MyFileStream.Length Dim Buffer(FileSize) As Byte MyFileStream.Read(Buffer, 0, MyFileStream.Length) MyFileStream.Close() Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition", "attachment; filename=" & filename & " .xls") Response.BinaryWrite(Buffer) End Sub Public Function CreateExcelWorkbook(ByVal strFileName As String) As Boolean Dim oXL As Excel.Application

    S 1 Reply Last reply
    0
    • N nagalakshmibasireddy

      hello, The code shown below is for excel sheet generation but when i execute this i am getting an error as access is denied .plz go though the code and if any mistake plz correct it .... Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click da1.MissingSchemaAction = MissingSchemaAction.AddWithKey CMD.Connection = con con.Open() CMD.CommandType = CommandType.StoredProcedure CMD.CommandText = "ACE_CONTROLTOWER" Dim cellid As New SqlParameter Dim fromDATE As New SqlParameter 'Dim tomonth As New SqlParameter 'Dim fromyear As New SqlParameter Dim toDATE As New SqlParameter cellid.ParameterName = "@CELLID" cellid.SqlDbType = SqlDbType.VarChar cellid.Value = TextBox1.Text cellid.Direction = ParameterDirection.Input CMD.Parameters.Add(cellid) fromDATE.ParameterName = "@fromDATE" fromDATE.SqlDbType = SqlDbType.DateTime fromDATE.Value = TextBox2.Text fromDATE.Direction = ParameterDirection.Input CMD.Parameters.Add(fromDATE) toDATE.ParameterName = "@toDATE" toDATE.SqlDbType = SqlDbType.DateTime toDATE.Value = TextBox5.Text toDATE.Direction = ParameterDirection.Input CMD.Parameters.Add(toDATE) Dim dr As SqlDataReader dr = CMD.ExecuteReader() DataGrid2.DataSource = dr DataGrid2.DataBind() dr.Close() 'closing data reader CMD.Dispose() con.Close() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click bln = CreateExcelWorkbook("example") '= Server.MapPath(".") + "\PWReports\" filePath = "c:\" filename = "example" filePath = filePath & filename & ".xls" Dim MyFileStream As FileStream = New FileStream(filePath, FileMode.Open) Dim FileSize As Long FileSize = MyFileStream.Length Dim Buffer(FileSize) As Byte MyFileStream.Read(Buffer, 0, MyFileStream.Length) MyFileStream.Close() Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition", "attachment; filename=" & filename & " .xls") Response.BinaryWrite(Buffer) End Sub Public Function CreateExcelWorkbook(ByVal strFileName As String) As Boolean Dim oXL As Excel.Application

      S Offline
      S Offline
      Sufyan_shani
      wrote on last edited by
      #2

      hi! as far as i think ur connection object is faulty create cnnection object with appropriate parameters.. like if u r using sqlconnection it would be dim constr as string="server=[servername];user Id=[username/sa];password=[pwd/""]initial catalog=[database name];" dim con as new sqlconnecton(constr) better if u would send connecton code as well.. GoodLuck!! Sufyan

      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