regarding excel sheet
-
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
-
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
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