Tuesday 22 February 2011

Run Sql Bunch From .net

   Public Sub PrepareSqlProcedure(ByVal ConString As String)
        Dim Dt_Check As New DataTable
        Try
            Dim ObjDataHandler As Object
            Dim strExePath As String
            Dim strpath As String
            Dim intPer As Short
            Dim fnum, intCount As Short
            Dim arrStr() As String
            Dim strFileText As String
            Dim strLocalConnect As String
            ' On Error GoTo errhandler
            'ObjSysCon = New ClsConnection
            'ObjSysCon.OpenConnection(ConString)
            Dt_Check = ObjSysCon.Getdatatable_New("Select * From Sysobjects Where XType='p' and Name='Shift_Summary'")
            If Dt_Check.Rows.Count > 0 Then
                'Nothing
            Else
                Dim sSql As String
                strpath = My.Application.Info.DirectoryPath & "\Script\Script.sql"
                fnum = FreeFile()
                FileOpen(fnum, strpath, OpenMode.Input)
                strFileText = InputString(fnum, LOF(fnum))
                FileClose(fnum)

                'Dim Dt As New DataSet
                'strFileText = ""
                'ObjSysCon.ExcuteQuery(Dt, "Select * from ViewOrange_SP")
                'strFileText = EnCrypt(Dt.Tables(0).Rows(0)("SP").ToString)
                arrStr = Split(strFileText, "GO")

                Dim dblVal As Double
                For intCount = 0 To UBound(arrStr) - 1
                    ' intPer = System.Math.Round((CDbl(intCount) * 100) / CDbl(UBound(arrStr)), 0)
                    System.Windows.Forms.Application.DoEvents()
                    If arrStr(intCount).ToString.Length <> 0 Then
                        If ObjSysCon.ExcuteCommand(arrStr(intCount)) = False Then
                            'GoTo errhandler
                            'Throw ex
                        End If
                    Else
                       Msg.Box(intCount.ToString)
                    End If
                Next
            End If
        Catch ex As Exception
        Finally
        End Try
    End Sub