Not getting results in datagrid view

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dougancil
    Contributor
    • Apr 2010
    • 347

    Not getting results in datagrid view

    I have two forms and I'm trying to pass a declared variable from form1 to form2 and then pass that variable in a sql query that I have in a dataset that is bound to my form. I know that my query works but it's not producing any data. I have debugged my form and can see the data being passed in the variables elsewhere on the page but I'm not sure of the syntax within the query. Can someone please offer assistance.

    My variables are declared in a module:

    Code:
    Public Module myGlobalVars
        Public payPeriodStartDate As New System.DateTime
        Public payPeriodEndDate As New System.DateTime
    End Module
    and here is form1:
    Code:
    Imports System.Data.SqlClient
    
    Public Class Main
        Dim instForm2 As New Exceptions
        Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startpayrollButton.Click
            Dim ssql As String = "select MAX(payrolldate) AS [payrolldate], " & _
                     "dateadd(dd, ((datediff(dd, '17530107', MAX(payrolldate))/7)*7)+7, '17530107') AS [Sunday]" & _
                      "from dbo.payroll" & _
                      " where payrollran = 'no'"
            Dim oCmd As System.Data.SqlClient.SqlCommand
            Dim oDr As System.Data.SqlClient.SqlDataReader
    
            oCmd = New System.Data.SqlClient.SqlCommand
            Try
                With oCmd
                    .Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=xxxxx;Data Source=xxxxx;uid=xxxxx;password=xxxxx")
                    .Connection.Open()
                    .CommandType = CommandType.Text
                    .CommandText = ssql
                    oDr = .ExecuteReader()
                End With
                If oDr.Read Then
                    payPeriodStartDate = oDr.GetDateTime(1)
                    payPeriodEndDate = payPeriodStartDate.AddDays(7)
                    Dim ButtonDialogResult As DialogResult
                    ButtonDialogResult = MessageBox.Show("      The Next Payroll Start Date is: " & payPeriodStartDate.ToString() & System.Environment.NewLine & "            Through End Date: " & payPeriodEndDate.ToString())
                    If ButtonDialogResult = Windows.Forms.DialogResult.OK Then
    
                        exceptionsButton.Enabled = True
                        startpayrollButton.Enabled = False
    
                    End If
                End If
                oDr.Close()
                oCmd.Connection.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                oCmd.Connection.Close()
            End Try
    
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exceptionsButton.Click
            Exceptions.Show()
        End Sub
    
        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            EmployeeEditform.Show()
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    End Class
    and here is form 2 sql query:
    Code:
    SELECT Employeenumber, Exceptiondate, Starttime, Endtime,Duration, Code, Submittedby FROM Exceptions   
    WHERE [Exceptions].exceptiondate   >= '" & payperiodStartDate &   
    "' and [Exceptions].exceptiondate <='" & payPeriodEndDate & "'

    The sql query works as I've debugged it within the form itself and I can see the correct data being presented, but it's just not showing up in the datagrid view. Any help would be greatly appreciated.

    Thank you,

    Doug
Working...