Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

VB.NET code to open an Access table and save as excel document I need a code tha

ID: 3776880 • Letter: V

Question

VB.NET code to open an Access table and save as excel document I need a code that can let me open any access table in my datagridview window in vb.net. In a way that I can type in the name of the table in a text field and when I open the file the table will show up in vb.net. I then need to be able to save the access document I opened as an excel file.

The form should look like this I type in the table i want, in this case Authors

I click the open button to open the browse window to select the access file

and the table shows up in the vb.net form

Authors Open Save

Explanation / Answer

COnnection Strings :

<connectionStrings>

<add name="Excel103conString

connectionString="provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};

Extended Properties='Excel 8.0;HDR={1}'"/>

<add name="Excel07ConString"

connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};

Extended Properties='Excel 8.0;HDR={1}'"/>

</connectinStrings>

//FrontEnd Design :

<asp : FileUpload ID="FileUpload1" runat="server" />

<asp : Button ID="btnupload" runat="server" Text="Upload" />

<br/>

<asp:Label ID="label1" runat="server" Text="Has Header ?"/>

<asp : GridView ID="GridView1" runat="server" AllowPaging="true">

</asp:GridView>

//Import to Gridview..

Private Sub Import_to_Grid(ByVal FilePath AS String,ByVal Extension As String, ByVal isHDR As String)

Dim conStr As String= " "

Select Case Extensin

Case ".xls"

'Excel 97-03

conStr=ConfigurationManager.ConnectionStrings("Excel03ConString")_

.ConnectionString

Exit Select

Case ".xlsx"

'Excel 07

conStr=ConfigurationManager.ConnectionStrings("Excel07ConString")_

.ConnectionString

Exit Select

End Select

cmdExcel.Connection=connExcel

connExcel.Open()

Dim dtExcelSchema As DataTable

connExcel.Close()

//Export to Excel

Protected Sub ExporttoExcel(Sender As Object, e As EventArgs)

Response.Clear()

Reesponse.Buffer=True

Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls")

Response.Charset=" "

Response.ContentType="application/vnd.ms-excel"

Using sw As New StrinWriter()

Dim hw As New HtmlTextWriter(sw)

GridView1.AlloPaging=False

Me.BindGrid()

GridView1.HeaderRow.BackColor=Color.White

For Each cell As TableCell In GridView1.HeaderRow.Cells

cell.BackColor=GridView1.HeaderStyle.BackColor

Next

For Each row As GridViewRow In GridVIew1.Rows

row.BaclColor=COlor.White

For Each cell As TableCell In row.Cells

If row.RowINdex Mod 2=0 Then

cell.BackColor=Gridview1.AlternatingRowStyle.BackColor

Else

cell.BackColor = GridVIew1.RowStyle.BackColor

End If

cell.CssClass = "textmode"

Next

Next

GridVirew1.RenderControl(hw)

End Using

End Sub

Public Overrides Sub VerifyRenderringInServerForm( control As Control )

' Verifies that the control is rendered

End Sub