Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 16th, 2007, 3:29 PM   #1
paulchwd
Hobbyist Programmer
 
paulchwd's Avatar
 
Join Date: Mar 2005
Posts: 139
Rep Power: 4 paulchwd is on a distinguished road
Datagrid

Hello All, when I run my code, I get a datagrid with a column(correct), but no data in it......


code:

** Please note, all this code is launched from form_load
(in bold)

Imports System
Imports System.IO
Imports System.Data
Imports System.Data.OleDb


Public Class qid_search

    
    Public Function getQueryString() As String
        Dim oApp As Microsoft.Office.Interop.Outlook.Application = New Microsoft.Office.Interop.Outlook.Application()
        Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = oApp.GetNamespace("mapi")
        Dim objNS As Microsoft.Office.Interop.Outlook._NameSpace = oApp.Session
        Dim qidFolder As Microsoft.Office.Interop.Outlook.MAPIFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox).Folders("QID")
        Dim oItems As Microsoft.Office.Interop.Outlook.Items = qidFolder.Items

        ' Dim mail As Microsoft.Office.Interop.Outlook.MailItem
        Dim mail As Object
        Dim email_address As String

        If (xlsFileLocation = "") Then
            MsgBox("Please select an excel file from the main screen first, and try again. Thank you", MsgBoxStyle.Critical, "QID E-mailer")
            Return Nothing
        End If

        Dim goHere As Boolean = True
        Dim getQid As String = "SELECT QID FROM [Sheet1$] WHERE [Name] = "
        Dim andVal As String = " and [Name] = "
        Dim singleQuote As String = "'"


        For i As Integer = 1 To oItems.Count

            mail = oItems.Item(i)
            'if its not a report item (returned mail) ... skip over it
            If (TypeOf mail Is Microsoft.Office.Interop.Outlook.ReportItem) Then

                email_address = extract_email_address(mail.Body, " ") ' stop char is a blank space

                Dim name As String = get_name_from_email(email_address)
                ' the word and is not in the query string and thus its the first one
                If (goHere) Then
                    getQid = getQid & singleQuote & name & singleQuote
                    goHere = False
                Else
                    getQid = getQid & andVal & singleQuote & name & singleQuote
                End If
         
            End If
        Next

        Return getQid
    End Function

    Public Sub doDataGrid()
        Dim grid As DataGrid
        Dim table As String = "[Sheet1$]"

        grid = New DataGrid
        grid.Location = New Point(7, 39)
        grid.Size = New Size(360, 276)
        grid.Enabled = False
        grid.DataSource = getDataSource()
        grid.DataMember = table
        Controls.Add(grid)


    End Sub

    Public Function getDataSource() As DataSet

        Dim dataSetx As DataSet
        Dim adapter As OleDbDataAdapter
        Dim table As String = "[Sheet1$]"


        If (conn Is Nothing) Then
            connect_to_xls(Form1.xlsLocation.Text)
            conn.Open()
        ElseIf (conn.State <> ConnectionState.Open) Then
            conn.Open()
        End If

        dataSetx = New DataSet()
        adapter = New OleDbDataAdapter(getQueryString(), conn)
        adapter.Fill(dataSetx, table)

        Return dataSetx

    End Function

    Public Function extract_email_address(ByVal email As String, ByVal stopChar As String) As String
        Dim idxOfAt As Integer
        Dim idxofSpaceatBegin As Integer
        Dim idxofSpaceatEnd As Integer
        Dim currentIdx As Integer
        Dim currentChar As Char = ""
        Dim c As Char
        Dim result As String
        Dim NewResult As String

        idxOfAt = email.IndexOf("@")

        'find the @ in the string and keep going left untill you hit a space

        idxofSpaceatBegin = email.LastIndexOf(" ", idxOfAt)
        idxofSpaceatEnd = email.IndexOf(" ", idxOfAt)
        result = email.Substring(idxofSpaceatBegin, idxofSpaceatEnd - idxofSpaceatBegin).ToString()
        NewResult = ""
        For Each c In result
            Select Case c
                Case "A" To "Z", "a" To "z", "0" To "9", "@", "."
                    NewResult = NewResult & c
                Case Else
            End Select
        Next


        Return NewResult

    End Function

    Public Function get_name_from_email(ByVal email_address As String) As String

        Dim nameSeperator As String = "."
        Dim splitArray(1) As String
        Dim fName As String
        Dim lName As String

        'split the email address at the @ sign
        splitArray = email_address.Split("@")
        'split array will now = the split of the portion of the email before the @ (firstname.lastname)
        splitArray = splitArray(0).Split(nameSeperator)
        fName = splitArray(0)
        lName = splitArray(1)

        Return lName & ", " & fName

    End Function

    Private Sub qid_search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        getQueryString()
        doDataGrid()
    End Sub
End Class

getQid:

"SELECT QID FROM [Sheet1$] WHERE [Name] = 'KICHAK, DENNIS' and [Name] = 'SPECK, SHARON' and [Name] = 'HILLMER, STEVEN' and [Name] = 'BERRY, DENISE' and [Name] = 'HAYTON, KAREN' and [Name] = 'FOLEY, JESSIE' and [Name] = 'HOPKINS, BARBARA' and [Name] = 'SELEMIDIS, VIRGINIA' and [Name] = 'CHAN, CONNIE' and [Name] = 'DELOREY, WENDY' and [Name] = 'STIPANCIC, ANNE' and [Name] = 'GORDON, JIM' and [Name] = 'PORTER, VIRGINIA' and [Name] = 'FRITH, BEVERLEY' and [Name] = 'GRATTON, SUSAN' and [Name] = 'VEGTER, BARBARA' and [Name] = 'POTTS, PAULINE' and [Name] = 'CALDWELL, DOUG' and [Name] = 'AGGARWAL, VANITA' and [Name] = 'BEATTY, JOANN' and [Name] = 'WOODRUFF, SUSAN' and [Name] = 'RICE, CHRIS' and [Name] = 'SMITH, CRAIG' and [Name] = 'SULLIVAN, SHERRY'"
paulchwd is offline   Reply With Quote
Old Aug 21st, 2007, 3:29 PM   #2
Ben.Dougall
Programmer
 
Ben.Dougall's Avatar
 
Join Date: Jul 2007
Location: London, Ontario, Canada
Posts: 34
Rep Power: 0 Ben.Dougall is on a distinguished road
Send a message via MSN to Ben.Dougall
I have no idea what your code is doing, but from the above query string... the name is NEVER going to be all those things.

Select QID from [Sheet1$] WHERE [name] = 'KICHAK, DENNIS' or [Name] = 'SPECK, SHARON'

would return the qid for those 2 names, but not the rest. Like i said, not sure on what the code is doing, but that my query writing background makes me think thats the use.
__________________
My site :: http://www.freewebtown.com/dougalbe
I'll try to be nicer, if you try being smarter.
Ben.Dougall is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting a Datagrid to Excel problem Mortavitch Visual Basic .NET 0 Jul 14th, 2006 9:34 PM
updating DataGrid?? gpreetsingh Visual Basic .NET 1 Feb 20th, 2006 8:20 AM
String to Datagrid Ghost C# 8 Oct 21st, 2005 2:08 PM
How can I disable particular rows in a datagrid? HappyTomato C# 2 Aug 25th, 2005 3:48 PM
datagrid footer BigBill Visual Basic .NET 0 Aug 2nd, 2005 1:59 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:26 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC