Basically im having the error because the datareader is not finding any data to meet the query criteria. So it closes but returns nothing, how do i give back a message saying that there is no data? Code is Below
'This checks the date selected on the calendar and runs a query based on the selection
Sub Button1_Click(sender As Object, e As EventArgs)
If month(formatdatetime(calen
dar1.Selec
tedDate,0)
) = month(formatdatetime(syste
m.DateTime
.now,0)) or month(formatdatetime(calen
dar1.selec
tedDate,0)
) > month(formatdatetime(syste
m.DateTime
.now,0)) then
datagrid1.datasource = ""
datagrid1.databind()
Label1.text = "Please choose another date, at least a month back"
Else
datagrid1.datasource = Select_info(calendar1.sele
cteddate) ' DATA READER USED HERE
datagrid1.databind()
label1.text = "Select the campaign using the select button next to it to view detailed campaign information. You have selected campaign information from " & formatdatetime(Calendar1.S
electedDat
e,2) & " to " & formatdatetime(system.Date
time.now,2
) & "."
End if
End Sub
THIS IS THE FUNCTION used ABOVE :
Function Select_info(ByVal datesel As Date) As System.Data.IDataReader
Dim connectionString As String = "Provider=Microsoft.Jet.OL
EDB.4.0; Ole DB Services=-4; Data Source=DATASOURCE
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbCon
nection(co
nnectionSt
ring)
Dim queryString As String = "SQL QUERY where [Start_Dte] >= @datesel) order by start_dte desc"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCom
mand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_datesel As System.Data.IDataParameter
= New System.Data.OleDb.OleDbPar
ameter
dbParam_datesel.ParameterN
ame = "@datesel"
dbParam_datesel.Value = datesel
dbParam_datesel.DbType = System.Data.DbType.DateTim
e
dbCommand.Parameters.Add(d
bParam_dat
esel)
dbConnection.Open
Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(Sy
stem.Data.
CommandBeh
avior.Clos
eConnectio
n)
Return dataReader
End Function
Any help will be appreciated.
Thx
Start Free Trial