Click here to Skip to main content
15,889,909 members
Home / Discussions / Database
   

Database

 
QuestionHelp Creating a Temp Table Pin
Hulicat3-Sep-09 11:19
Hulicat3-Sep-09 11:19 
AnswerRe: Help Creating a Temp Table Pin
Blue_Boy3-Sep-09 11:23
Blue_Boy3-Sep-09 11:23 
GeneralRe: Help Creating a Temp Table Pin
Hulicat3-Sep-09 13:52
Hulicat3-Sep-09 13:52 
AnswerRe: Help Creating a Temp Table Pin
Niladri_Biswas6-Nov-09 20:24
Niladri_Biswas6-Nov-09 20:24 
QuestionHelp Needed: I have a dll (vb 2005) that I want to call in a SqlFunction that returns data from an Excel file Pin
JNBG3-Sep-09 10:16
JNBG3-Sep-09 10:16 
AnswerRe: Help Needed: I have a dll (vb 2005) that I want to call in a SqlFunction that returns data from an Excel file Pin
Abhishek Sur5-Sep-09 12:12
professionalAbhishek Sur5-Sep-09 12:12 
GeneralRe: Help Needed: I have a dll (vb 2005) that I want to call in a SqlFunction that returns data from an Excel file Pin
JNBG5-Sep-09 12:33
JNBG5-Sep-09 12:33 
GeneralRe: Help Needed: I have a dll (vb 2005) that I want to call in a SqlFunction that returns data from an Excel file Pin
JNBG5-Sep-09 14:17
JNBG5-Sep-09 14:17 
Abhishek,

Here is the class I am using (along with my AssemblyInfo file).   The only section at this point I am worrying about is the ExcelTester...I had the chgCardRead working by calling it in SQL on Monday, but again, something has gone wrong and I'm at a loss.   Also, I am creating the assemblies as Unsafe already.   Like I said before, it worked just fine and then just stopped and I have no idea why.   Thank you for your assistance.

Option Strict Off

Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Reflection
Imports System.Data
Imports System.IO
Imports System.Runtime.InteropServices
Imports System
Imports Microsoft.Win32
Imports System.Data.OleDb.OleDbPermission

<ComClass(ChargeCardCom.ClassId, ChargeCardCom.InterfaceId, ChargeCardCom.EventsId)> _
Public Class ChargeCardCom


#Region "COM GUIDs"
      ' These   GUIDs provide the COM identity for this class
      ' and its COM interfaces. If you change them, existing
      ' clients will no longer be able to access the class.
      Public Const ClassId As String = "2DF8ED1A-55D0-4EC1-AF8E-1611FF6C631E"
      Public Const InterfaceId As String = "14CA7221-FBFD-4D6C-92B3-E60EAD6B48D7"
      Public Const EventsId As String = "F994EEB1-4001-444C-BF01-09EA090B7CA6"

      'Public Const ClassId As String = "d05374f7-f2e0-4c82-badc-2f5f93c6f1b1"
      'Public Const InterfaceId As String = "b4d276c1-6548-4d70-9c05-e9e1e034c55a"
      'Public Const EventsId As String = "0d3e3508-c31e-45df-b41a-b4bd0997fcb4"
#End Region

      ' A creatable COM class must have a Public Sub New()
      ' with no parameters, otherwise, the class will not be
      ' registered in the COM registry and cannot be created
      ' via CreateObject.
      Public Sub New()
            MyBase.New()
      End Sub

      Public Shared Function ExcelTester() As String


            Log("in tester")


            Dim xlconn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\10098886-1509.xls;Extended Properties=""Excel 8.0;HDR=No;IMEX=1""")
            Dim xlda As New OleDbDataAdapter("select * from [Small Batch$]", xlconn)
            Dim xldt As New DataTable
            Log("about to open")

            xlda.Fill(xldt)
            Log("opened")

            xlda.Dispose()
            xlconn.Close()


      End Function


      '<Microsoft.SqlServer.Server.SqlFunction(FillRowMethodName:="FillCardReadRows")> _
      'Public Shared Function GetChargeData_InitMethod(ByVal Solution As String, ByVal Batch As String, _
      '      ByVal Charge As String, ByVal sqlinstance As String, ByVal sqldatabase As String) As IEnumerable
      '      'Public Shared Function InitMethod(ByVal logname As String) As IEnumerable

      '      'Dim err3() As String = {"-1~InInitMethod~0~0~0"}
      '      'Return New ArrayList(err3)

      '      Try
      '            'Return New EventLog(logname, Environment.MachineName).Entries

      '            WriteToLogFile("In GetChargeData_InitMethod ")

      '            'Dim err3() As String = {"-1~1WroteToFile~0~0~0"}
      '            'Return New ArrayList(err3)

      '            'If sqlinstance.Length = 0 Then
      '            '      Dim err1() As String = {"-1~SQLServerNotFound~0~0~0"}
      '            '      Return New ArrayList(err1)
      '            '      Exit Function
      '            'End If

      '            'If sqldatabase.Length = 0 Then
      '            '      Dim err2() As String = {"-1~DataBaseNotFound~0~0~0"}
      '            '      Return New ArrayList(err2)
      '            '      Exit Function
      '            'End If

      '            'strSQLServer = sqlinstance 'regKeySubFolder.GetValue("data source").ToString()
      '            'strSQLServerDatabase = sqldatabase 'regKeySubFolder.GetValue("initial catalog").ToString()

      '            'Dim err3() As String = {"-1~2SetDBInfo~0~0~0"}
      '            'Return New ArrayList(err3)

      '            'calling this here so that any future errors wille be logged
      '            'modErrorLog.SetConnectionParameters(sqldatabase, sqlinstance)
      '            Dim arr1() As String = chgCardRead(Solution, Batch, Charge, sqlinstance, sqldatabase)

      '            WriteToLogFile("After chgCardRead call from GetChargeData_InitMethod, there are " & CStr(arr1.Length) & " arrays lines returned")
      '            'WriteToLogFile("arr1 in InitMethod " & arr1(0).ToString)
      '            Return New ArrayList(arr1)
      '      Catch ex As Exception
      '            WriteToLogFile("In InitMethod Error Handler ")
      '            'modErrorLog.SetConnectionParameters(sqldatabase, sqlinstance)
      '            modErrorLog.LogErrorToSQL(ex.Message, "GetChargeData_InitMethod")
      '            Dim arr1() As String = {"-1~ExcInInitMethod~0~0~0"}
      '            Return New ArrayList(arr1)
      '      End Try
      'End Function

      ''Public Function chgCardRead(ByVal Solution As String, ByVal Batch As String, ByVal Charge As String) As DataSet
      'Public Shared Function chgCardRead(ByVal Solution As String, ByVal Batch As String, ByVal Charge As String, _
      '      ByVal sqlinstance As String, ByVal sqldatabase As String) As String()

      '      'Need to assign so there is no null reference
      '      'Dim ResultsArray() As String = {"-1~" & "strSearchMaterial" & "~" & "strSearchBatch" & "~~0~0~0"}
      '      Dim ResultsArray() As String = {"-1~ChargeNotFound~0~0~0"}

      '      'Dim Charge1 As Integer = Convert.ToInt32(Charge)
      '      'Dim Charge9 As Integer = (Convert.ToInt32(Charge) + 9).ToString()
      '      'Dim intChgRow As Integer = 0
      '      'Dim intChgCol As Integer = 0
      '      'Dim myDataset As New DataSet()
      '      Dim fileCheck As String = ""

      '      'Dim ChargeNumbers(9) As String
      '      'Dim retVal As Double = Charge Mod 10
      '      'If retVal <> 0 Then
      '      '      Dim SCharge As String = Charge.Substring(0, Charge.Length - 1)
      '      '      Charge = SCharge & "0"
      '      'End If

      '      'For i As Integer = Convert.ToInt32(Charge.Substring(Charge.Length - 1, 1)) To 9
      '      '      ChargeNumbers(i) = (Convert.ToInt32(Charge) + i).ToString()
      '      'Next

      '      Try

      '            If sqlinstance.Length = 0 Then
      '                  Dim err1() As String = {"-1~SQLServerNotFound~0~0~0"}
      '                  'Return New ArrayList(err1)
      '                  Return err1
      '                  'Exit Function
      '            End If

      '            If sqldatabase.Length = 0 Then
      '                  Dim err2() As String = {"-1~DataBaseNotFound~0~0~0"}
      '                  Return err2
      '                  'Exit Function
      '            End If

      '            strSQLServer = sqlinstance 'regKeySubFolder.GetValue("data source").ToString()
      '            strSQLServerDatabase = sqldatabase 'regKeySubFolder.GetValue("initial catalog").ToString()

      '            If Not InitializeApplicationSettings() Then
      '                  'insert interface error
      '                  ResultsArray(0) = "-1~ErrSettingSettings~0~0~0"
      '                  Return ResultsArray
      '            End If

      '            strNVPPath = strNVPPath & Solution & "-" & Batch & ".xls"

      '            fileCheck = Dir(strNVPPath)
      '            If fileCheck = "" Then
      '                  'myDataset = Nothing
      '                  'Return myDataset
      '                  'insert interface error
      '                  ResultsArray(0) = "-1~FileDNE~0~0~0"
      '                  Return ResultsArray
      '                  'Exit Function
      '            End If

      '            'strNVPPath = strNVPPath & Solution & "-" & Batch & ".xls"
      '            Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      '            "Data Source=" & strNVPPath & ";" & _
      '            "Extended Properties=""Excel 8.0;HDR=Yes; IMEX=1"""

      '            'Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
      '            '      strNVPPath & ";Extended Properties=""Excel 8.0;HDR=No;"""

      '            Dim conn1 As New System.Data.OleDb.OleDbConnection(strConn)
      '            conn1.Open()
      '            Dim cmd1 As New System.Data.OleDb.OleDbCommand("SELECT * FROM [" & _
      '                  strNVPSpreadSheet & "$] WHERE " & strChargeColumn & " BETWEEN '" & _
      '                  Charge & "' AND '" & CStr(CInt(Charge) + 9) & "'", conn1)

      '            Dim rdr As OleDbDataReader = cmd1.ExecuteReader

      '            If Not rdr.HasRows Then
      '                  'return error with mt data array
      '                  Return ResultsArray
      '            End If

      '            Dim intRowCounter As Integer = 0
      '            Dim strReturnValues

      '            Do While rdr.Read()
      '                  strReturnValues = ""
      '                  For i As Integer = 0 To rdr.FieldCount - 1
      '                        If i = strMaterialIDCol Or i = strRMNameCol Or i = strQtyCol Or i = strUOMCol Or i = strToleranceCol Then
      '                              Console.Write(rdr.Item(i) & "~")
      '                              strReturnValues &= rdr.Item(i) & "~"
      '                        End If
      '                  Next

      '                  Console.WriteLine(vbCrLf)
      '                  ReDim Preserve ResultsArray(intRowCounter)
      '                  ResultsArray(intRowCounter) = strReturnValues

      '                  intRowCounter += 1
      '            Loop

      '            'If intRowCounter = 0 Then
      '            '      'return error
      '            'End If

      '            rdr.Close()
      '            conn1.Close()

      '            'Dim a() As String = ResultsArray.Split("~")

      '            Return ResultsArray
      '      Catch ex As Exception
      '            LogErrorToSQL(ex.Message, "chgCardRead")
      '            Dim ErrorArray() As String = {"-1~ErrorInChgCardRead~0~0~0"}
      '            Return ErrorArray
      '      End Try
      'End Function

      'Public Shared Sub FillCardReadRows(ByVal obj As Object, <Out()> ByRef MaterialID As SqlString, <Out()> ByRef RMName As SqlString, <Out()> ByRef Quantity As SqlString, <Out()> ByRef UOM As SqlString, <Out()> ByRef Tolerance As SqlString)
      '      'Public Shared Sub FillRow(ByVal obj As Object, <Out()> ByRef timeWritten As SqlDateTime, <Out()> ByRef message As SqlChars, <Out()> ByRef category As SqlChars, <Out()> ByRef instanceId As Long)
      '      Try
      '            WriteToLogFile("In FillCardReadRows")

      '            Dim array As String = CType(obj, String)
      '            WriteToLogFile(array.ToString)
      '            Dim a() As String = array.Split("~")
      '            MaterialID = New SqlString(a(0))
      '            RMName = New SqlString(a(1))
      '            Quantity = New SqlString(a(2))
      '            UOM = New SqlString(a(3))
      '            Tolerance = New SqlString(a(4))
      '            'qualityinspect = New SqlString(a(5))
      '            'blocked = New SqlString(a(6))

      '            'Dim eventLogEnTry As EventLogEntry = CType(obj, EventLogEntry)
      '            'timeWritten = New SqlDateTime(eventLogEnTry.TimeWritten)
      '            'message = New SqlChars(eventLogEnTry.Message)
      '            'category = New SqlChars(eventLogEnTry.Category)
      '            'instanceId = eventLogEnTry.InstanceId
      '      Catch ex As Exception
      '            modErrorLog.LogErrorToSQL(ex.Message, "FillCardReadRows")
      '            WriteToLogFile("In FillCardReadRows Error Handler ")

      '            Dim array As String = CType(obj, String)
      '            Dim a() As String = array.Split("~")
      '            MaterialID = New SqlString(a(0))
      '            RMName = "ErrFillCardReadRows"
      '            Quantity = New SqlString(a(2))
      '            UOM = New SqlString(a(3))
      '            Tolerance = New SqlString(a(4))
      '      End Try
      'End Sub

      Public Shared Sub Log(ByVal msg As String)
            Dim SW As StreamWriter = File.AppendText("C:\jeffcccom.txt")

            SW.WriteLine(msg & " : " & Now())
            SW.Flush()
            SW.Close()

      End Sub
End Class


Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("ChargeCardCom")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("ChargeCardCom")>
<Assembly: AssemblyCopyright("")>
<Assembly: AssemblyTrademark("")>

<Assembly: ComVisible(True)>

'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("8068fffd-907a-44ec-b51c-a9dc0e7b3ecf")>
'<Assembly: Guid("1306f111-0f59-4a60-a826-78034ab8651d")>

' Version information for an assembly consists of the following four values:
'
'         Major Version
'         Minor Version
'         Build Number
'         Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>
QuestionHelp for an SQL query Pin
sazd13-Sep-09 3:40
sazd13-Sep-09 3:40 
AnswerRe: Help for an SQL query Pin
David Skelly3-Sep-09 6:03
David Skelly3-Sep-09 6:03 
GeneralRe: Help for an SQL query Pin
sazd13-Sep-09 8:35
sazd13-Sep-09 8:35 
GeneralRe: Help for an SQL query Pin
David Skelly3-Sep-09 22:34
David Skelly3-Sep-09 22:34 
Questioneasy_odbc leak memory Pin
Ruscoff3-Sep-09 0:05
Ruscoff3-Sep-09 0:05 
AnswerRe: easy_odbc leak memory Pin
Ashfield3-Sep-09 1:30
Ashfield3-Sep-09 1:30 
GeneralRe: easy_odbc leak memory Pin
Ruscoff3-Sep-09 2:47
Ruscoff3-Sep-09 2:47 
GeneralRe: easy_odbc leak memory Pin
Ashfield3-Sep-09 3:36
Ashfield3-Sep-09 3:36 
QuestionScript Check Pin
Mustafa Ismail Mustafa2-Sep-09 9:46
Mustafa Ismail Mustafa2-Sep-09 9:46 
AnswerRe: Script Check Pin
Mycroft Holmes2-Sep-09 18:06
professionalMycroft Holmes2-Sep-09 18:06 
GeneralRe: Script Check Pin
Mustafa Ismail Mustafa2-Sep-09 20:47
Mustafa Ismail Mustafa2-Sep-09 20:47 
Questionupdate issue Pin
Tauseef A2-Sep-09 2:30
Tauseef A2-Sep-09 2:30 
AnswerRe: update issue Pin
Blue_Boy2-Sep-09 2:38
Blue_Boy2-Sep-09 2:38 
AnswerRe: update issue Pin
David Mujica2-Sep-09 3:32
David Mujica2-Sep-09 3:32 
AnswerRe: update issue Pin
Abhishek Sur2-Sep-09 9:43
professionalAbhishek Sur2-Sep-09 9:43 
AnswerRe: update issue Pin
Niladri_Biswas2-Sep-09 17:18
Niladri_Biswas2-Sep-09 17:18 
Questione-blood bank Pin
noo.dyab2-Sep-09 1:07
noo.dyab2-Sep-09 1:07 

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.