| | |
how to import data from SQL database to excell?
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2008
Posts: 30
Reputation:
Solved Threads: 0
can u spot the error in this code..
VB.NET Syntax (Toggle Plain Text)
Private Sub fncExcelExport(ByVal strSql As String) 'fncExcelExport("SELECT * FROM tbl_rop WHERE Name_User ='" & (TextBox1.Text) & "', Date_of_birth= '" & (TextBox2.Text) & "' , Hobbies='" & (TextBox3.Text) & "' , Phone_Number ='" & (TextBox4.Text) & "' where Name_User = '" & (TextBox1.Text) & "'") Dim dsExcelExport As New DataSet Dim daExcelExport As New SqlDataAdapter Dim Excel As New Excel.Application Dim intColumn, intRow, intColumnValue As Integer Dim strExcelFile As String Dim strFileName As String Dim conCurrent As New SqlConnection conCurrent = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1") 'conCurrent = New SqlConnection("server=;(local) catalog=ROP1;User ID=sa;Password=") daExcelExport = New SqlDataAdapter(strSql, conCurrent) varCommand = New SqlCommand(strSql, varConnection) daExcelExport = New SqlDataAdapter(varCommand) daExcelExport.Fill(dsExcelExport) Dim strAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location.Substring(0, System.Reflection.Assembly.GetExecutingAssembly.Location.LastIndexOf("\") + 1) With Excel .SheetsInNewWorkbook = 1 .Workbooks.Add() .Worksheets(1).Select() 'For displaying the column name in the the excel file. For intColumn = 0 To dsExcelExport.Tables(0).Columns.Count - 1 .Cells(1, intColumn + 1).Value = dsExcelExport.Tables(0).Columns(intColumn).ColumnName.ToString Next 'For displaying the column value row-by-row in the the excel file. For intRow = 0 To dsExcelExport.Tables(0).Rows.Count - 1 For intColumnValue = 0 To dsExcelExport.Tables(0).Columns.Count - 1 .Cells(intRow + 1, intColumnValue + 1).Value = dsExcelExport.Tables(0).Rows(intRow).ItemArray(intColumnValue).ToString Next Next strFileName = InputBox("Please enter the file name.", " ") strExcelFile = strAppPath & "tbl_rop" .ActiveWorkbook().SaveAs(strExcelFile) .ActiveWorkbook.Close() .AddChart() End With MessageBox.Show("File exported sucessfully.", "Exporting done", MessageBoxButtons.OK, MessageBoxIcon.Information) NormalExit: Excel.Quit() Excel = Nothing GC.Collect() Exit Sub End Sub
•
•
Join Date: Apr 2008
Posts: 30
Reputation:
Solved Threads: 0
this the line which the error occur...
daExcelExport.Fill(dsExcelExport)
i think the error come from the connection bridge that i created earlier at form_load....
fncExcelExport("SELECT Name_User ='" & (TextBox1.Text) & "', Date_of_birth= '" & (TextBox2.Text) & "' , Hobbies='" & (TextBox3.Text) & "' , Phone_Number ='" & (TextBox4.Text) & "' where Name_User = '" & (TextBox1.Text) & "'")
daExcelExport.Fill(dsExcelExport)
i think the error come from the connection bridge that i created earlier at form_load....
fncExcelExport("SELECT Name_User ='" & (TextBox1.Text) & "', Date_of_birth= '" & (TextBox2.Text) & "' , Hobbies='" & (TextBox3.Text) & "' , Phone_Number ='" & (TextBox4.Text) & "' where Name_User = '" & (TextBox1.Text) & "'")
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Register an application
- Next Thread: Accessing data in a datagrid...
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add advanced application array assignment basic binary box button buttons center click code combo connectionstring convert cpu data database databasesearch datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity pan peertopeervideostreaming picturebox picturebox2 port print printpreview read record regex reports" reuse right-to-left save savedialog search serial socket sorting sqldatbase storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet vista visual visualbasic visualbasic.net visualstudio.net web wpf xml





