Click here to Skip to main content
15,890,438 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: VB code for sending an email through .net application using smtp Pin
Jon_Boy1-Oct-08 9:10
Jon_Boy1-Oct-08 9:10 
GeneralRe: VB code for sending an email through .net application using smtp Pin
Tom Deketelaere1-Oct-08 9:12
professionalTom Deketelaere1-Oct-08 9:12 
GeneralRe: VB code for sending an email through .net application using smtp Pin
lostboy2411-Oct-08 14:50
lostboy2411-Oct-08 14:50 
QuestionVB.NET: Import Excel Data into SQL (Error: Could not find installable ISAM.) Pin
Indra PR1-Oct-08 2:40
Indra PR1-Oct-08 2:40 
AnswerRe: VB.NET: Import Excel Data into SQL (Error: Could not find installable ISAM.) Pin
Ashfield1-Oct-08 3:40
Ashfield1-Oct-08 3:40 
GeneralRe: VB.NET: Import Excel Data into SQL (Error: Could not find installable ISAM.) Pin
Ashfield1-Oct-08 3:42
Ashfield1-Oct-08 3:42 
GeneralRe: VB.NET: Import Excel Data into SQL (Error: Could not find installable ISAM.) Pin
Paul Conrad1-Oct-08 10:13
professionalPaul Conrad1-Oct-08 10:13 
GeneralRe: VB.NET: Import Excel Data into SQL (Error: Could not find installable ISAM.) Pin
Indra PR2-Oct-08 0:50
Indra PR2-Oct-08 0:50 
I tried to follow your code and modified it with a data reader.

Public Function ExecuteQuery(ByVal query As String) As Boolean
    Dim con As System.Data.OleDb.OleDbConnection
    Dim cmd As System.Data.OleDb.OleDbCommand

    con = New System.Data.OleDb.OleDbConnection(DSN)
    cmd = New System.Data.OleDb.OleDbCommand(query, con)
    cmd.CommandType = CommandType.Text

    Try
        con.Open()
        cmd.ExecuteNonQuery()
    Catch ex As Exception
        Throw ex
    Finally
        con.Close()
    End Try

    Return True
End Function

Private Function frmUploader_upload() As Boolean
    Dim strConnection As String
    Dim strCommand As String
    Dim query As String
    Dim excelConnection As System.Data.OleDb.OleDbConnection
    Dim excelCommand As System.Data.OleDb.OleDbCommand
    Dim dr As System.Data.OleDb.OleDbDataReader
    Dim dt As New DataTable
    Dim i As Integer = 0

    strConnection = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Extended Properties=Excel 8.0;Persist Security Info=False", Me.tbFile.Text)
    excelConnection = New System.Data.OleDb.OleDbConnection(strConnection)
    strCommand = String.Format("SELECT * FROM [{0}$]", Me.cbSheet.Text)
    excelCommand = New System.Data.OleDb.OleDbCommand(strCommand, excelConnection)

    Try
        excelConnection.Open()
        dr = excelCommand.ExecuteReader
        While dr.Read
            query = String.Format("INSERT INTO Sl_Logproof_200311 VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}',{18},{19},{20},{21},'{22}',{23},{24},'{25}','{26}','{27}',{28})", _
            ReplaceQuote(dr(0).ToString), ReplaceQuote(dr(1).ToString), ReplaceQuote(dr(2).ToString), ReplaceQuote(dr(3).ToString), ReplaceQuote(dr(4).ToString), ReplaceQuote(dr(5).ToString), ReplaceQuote(dr(6).ToString), ReplaceQuote(dr(7).ToString), ReplaceQuote(dr(8).ToString), ReplaceQuote(dr(9).ToString), ReplaceQuote(dr(10).ToString), _
            ReplaceQuote(dr(11).ToString), ReplaceQuote(dr(12).ToString), ReplaceQuote(dr(13).ToString), ReplaceQuote(dr(14).ToString), ReplaceQuote(dr(15).ToString), ReplaceQuote(dr(16).ToString), ReplaceQuote(dr(17).ToString), IsEmptyText(dr(18).ToString, "0"), IsEmptyText(dr(19).ToString, "0"), IsEmptyText(dr(20).ToString, "0"), _
            IsEmptyText(dr(21).ToString, "0"), ReplaceQuote(dr(22).ToString), IsEmptyText(dr(23).ToString, "0"), IsEmptyText(dr(24).ToString, "0"), ReplaceQuote(dr(25).ToString), ReplaceQuote(dr(26).ToString), ReplaceQuote(dr(28).ToString), ReplaceQuote(dr(27).ToString))
            ExecuteQuery(query)
            If i Mod 1000 = 0 Then
                Me.tsStatus.Text = String.Format("{0} Rows have been transformed or copied.", i)
            End If
            i += 1
        End While
    Catch ex As Exception
        MsgBox(ex.Message)
        Return False
    Finally
        excelConnection.Close()
    End Try

    Return True
End Function


It can copy now, but is there any better way? With this code, it still takes too much time to import and it needs 2 connections. Using SQL Server DTS is a lot faster.


Best Regards,
Indra Permana Rusli

GeneralRe: VB.NET: Import Excel Data into SQL (Error: Could not find installable ISAM.) Pin
Ashfield2-Oct-08 8:39
Ashfield2-Oct-08 8:39 
GeneralRe: VB.NET: Import Excel Data into SQL (Error: Could not find installable ISAM.) Pin
Indra PR5-Oct-08 18:44
Indra PR5-Oct-08 18:44 
GeneralRe: VB.NET: Import Excel Data into SQL (Error: Could not find installable ISAM.) Pin
Ashfield6-Oct-08 1:35
Ashfield6-Oct-08 1:35 
AnswerRe: VB.NET: Import Excel Data into SQL (Error: Could not find installable ISAM.) Pin
Paddy Boyd2-Oct-08 2:31
Paddy Boyd2-Oct-08 2:31 
QuestionProblem in retrieving computer information in the active directory Pin
Chaitanya kumar CVSS1-Oct-08 2:37
Chaitanya kumar CVSS1-Oct-08 2:37 
QuestionConection to SQLExpress Server Pin
nitin_ion30-Sep-08 22:49
nitin_ion30-Sep-08 22:49 
AnswerRe: Conection to SQLExpress Server Pin
Guffa30-Sep-08 23:08
Guffa30-Sep-08 23:08 
GeneralRe: Conection to SQLExpress Server Pin
nitin_ion30-Sep-08 23:11
nitin_ion30-Sep-08 23:11 
GeneralRe: Conection to SQLExpress Server Pin
Guffa1-Oct-08 3:01
Guffa1-Oct-08 3:01 
AnswerRe: Conection to SQLExpress Server Pin
jzonthemtn1-Oct-08 1:07
jzonthemtn1-Oct-08 1:07 
AnswerRe: Conection to SQLExpress Server Pin
Anoop Brijmohun1-Oct-08 1:48
Anoop Brijmohun1-Oct-08 1:48 
GeneralRe: Conection to SQLExpress Server Pin
nitin_ion1-Oct-08 1:50
nitin_ion1-Oct-08 1:50 
QuestionChange back color of selected dates in Month calender control in vb.net Pin
~Khatri Mitesh~30-Sep-08 21:43
~Khatri Mitesh~30-Sep-08 21:43 
AnswerRe: Change back color of selected dates in Month calender control in vb.net Pin
HemJoshi1-Oct-08 1:18
HemJoshi1-Oct-08 1:18 
QuestionCreate database table directly from a dataset which has many no. of data table [modified] Pin
snehasish30-Sep-08 21:39
snehasish30-Sep-08 21:39 
AnswerRe: Create database table from a dataset which has no of data table Pin
C1AllenS30-Sep-08 23:10
C1AllenS30-Sep-08 23:10 
GeneralRe: Create database table from a dataset which has many no. of data table Pin
snehasish1-Oct-08 0:57
snehasish1-Oct-08 0:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.