I have a grid that gets filterd based on two drop down lists. One has managers names the other has week Ending Dates. I want to loop through the grid and find a value in column 'Timesheet' where it it 'NOT IN'. if so then grab their name which is columns ResourceFirstName and ResourceLastName.
DougP
Code:
this is in page load
Dim SQLString As String = FillGridWhoseinsofarWithSQL(Me.ddlManagerName.Text,
Me.ddlWeekEndDate.Text,
"Counter",
ViewState("SortDirection"))
Me.GridView1.DataSource = PopulateGridwithSQL(SQLString)
Me.GridView1.DataBind()
'-------------
Private Function FillGridWhoseinsofarWithSQL(ByVal Manager,
ByVal WeekEndDate,
ByVal SortColumn,
ByVal SortDirection)
Dim SQLString As String = ""
If SortColumn = vbNullString Then
SortColumn = "ResourcelastName"
End If
If SortDirection = vbNullString Then
SortDirection = "ASC"
End If
If Manager = "Choose..." Then
sp_SOWInsertWeekAtAGlance("NULL", WeekEndDate) 'NOTE this is "NULL" in quotes which the SP is looking for
Else
sp_SOWInsertWeekAtAGlance(Manager, WeekEndDate)
End If
SQLString = "Select ROW_NUMBER() OVER (ORDER BY WAGM.Vendor,WAGM.ResourceLastName,WAGM.ResourceFirstName) AS Counter, " & _
"WAGM.Vendor,WAGM.ResourceLastName, WAGM.ResourceFirstName, WAGM.Manager, " & _
" WAG.TotalHours, " & _
"Convert(nvarchar(12),WAG.WeekEndDate,101) AS WeekEndDate, " & _
"'Timesheet' = " & _
"Case " & _
"When WAG.ResourceFirstName IS NULL Then 'NOT IN' " & _
"Else 'IN' " & _
" End , convert(nvarchar(12),WAG.TimeSheetSubmittedDate,101) as DateSubmitted " & _
"From WeekAtAGlanceMissing WAGM " & _
"left join WeekAtAGlance WAG ON " & _
"WAGM.ResourceLastName = WAG.ResourceLastName " & _
"And " & _
"WAGM.ResourceFirstName = WAG.ResourceFirstName " & _
"Where WAGM.Vendor is not null"
FillGridWhoseinsofarWithSQL = SQLString
End Function
'-------------------
Public Function PopulateGridwithSQL(ByVal SQLStatement As String)
Dim Conn As SqlConnection
'use ConnectionString from WEB config file
Dim connStr As String = ConfigurationManager.ConnectionStrings("SOWTimeReportingConnectionString").ConnectionString
Conn = New SqlConnection(connStr)
Conn.Open()
Dim daTrans As New SqlDataAdapter
Dim dtTrans As New DataTable
daTrans.SelectCommand = New SqlCommand(SQLStatement, Conn)
daTrans.Fill(dtTrans)
'
Return dtTrans
Conn = Nothing
End Function
DougP