hello vb elites
please i need help!! i want to use the values inside my datagridview colume. what i want to do is this, i have a date column, and i time column. so i want to check if the date is today and if the time is now, then send a message!

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Me.Label1.Text = TimeOfDay


Dim i As Integer
Dim a As String

For i = 0 To ReminderTblDataGridView.Rows.Count - 1
a = ReminderTblDataGridView.Item(2, i).Value.ToString()
If a = Now.Date.ToString() And Me.Label1.Text = ReminderTblDataGridView.Item(3, i).Value Then

" message code

end if
next
end sub
end class

ReminderTblDataGridView is the name of my datagridview
i am using i to loop
i am using a to collect the date from the datagridview and compare with now
me.label1 to check if the content in the time column is now


pls help or give me any idea

is there is any error in it ? what is your prob please be more specific.

there is no error when its in the form load event, but it dos'nt work either. it generates error in the time_tick event

where should i run the code, timer or load event???

can you please post the snap shoot of your form , and code behined it., and the error i think is that you are taking time of the day , its mean hh-mm-ss-ms , so it will not execute , until your condition is true , so i think you have to take hh-mm instead of time of day , may be this will solve your pron , other wise , if you post the form's snap shoot and code then i will try to provide you an working example.

Regards

hey check while debugging whats that time of day Returns 2 u ...

and pls post ere whats the Date And time values shows in DataGridView Column

@waqasaslammmeo i attached it. and thank you all for trying to help me.

the datagrid view have 7 rows. but i only need values from the date and time.

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Me.Label1.Text = TimeOfDay
Dim i As Integer
Dim a As Date
For i = 0 To ReminderTblDataGridView.Rows.Count - 1
a = ReminderTblDataGridView.Item(2, i).Value
If a = Now.Date And Me.Label1.Text = ReminderTblDataGridView.Item(3, i).Value Then

Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("username@gmail.com", "password")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("YOURusername@gmail.com")
mail.To.Add("TOADDRESS")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try

end if
next

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ReminderSystemDataSet.ReminderTbl' table. You can move, or remove it, as needed.
Me.ReminderTblTableAdapter.Fill(Me.ReminderSystemDataSet.ReminderTbl)

i think it is better to take a datetime picker instead of label and then set the format property as custom , and set custom property as hh:mm then you will get the time like this 2:33 , now after this , just compare the time in your grid like this , and if it shows any error and not works then add :00 as string , as i showing you in my code . check this out

dim i as integer


for i = 0 to datagridview.rows.count-1
dim a as string 
a = datetimepicker.text & ":00"
if a = datagridview.item(6,i).value.tostring() and  now.date.tostring = datagridview.item(2,i).value.tostring()
    //place your email sending code here 
end if 

next

if you find any error in it , then please do tel me .

Regards

it gave this error: Object reference not set to an instance of an object.
at line 8:" if a = datagridview.item(6,i).value.tostring() and now.date.tostring = datagridview.item(2,i).value.tostring() "

dim i as integer


for i = 0 to datagridview.rows.count-1
dim a as string
a = datetimepicker.Value.ToString("HH:mm:ss")
'OR it depend on ur time format i.e 24 hrs or 12 hrs
if a = datagridview.item(6,i).value.tostring() and Now.Date.ToString("MM/dd/yyyy") = datagridview.item(2,i).value.tostring()
//place your email sending code here
end if

Try this Out
next

dim i as integer


for i = 0 to datagridview.rows.count-1
dim a as string 
a = datetimepicker.Value.ToString("HH:mm:ss")
'OR it depend on ur time format i.e 24 hrs or 12 hrs 
if a = datagridview.item(6,i).value.tostring() and Now.Date.ToString("MM/dd/yyyy") = datagridview.item(2,i).value.tostring()
//place your email sending code here 
end if

try this

ok check this put , hope this will works fine.

dim i as integer
for i = 0 to datagridview.rows.count-1
dim a,b as string 
a = datetimepicker.text & ":00"
b = now.date.tostring()
if a = datagridview.item(6,i).value.tostring() and  b = datagridview.item(2,i).value.tostring()
    //place your email sending code here 
end if 

next

Regards

@waqasaslammmeo .... i realy appretiate ur code bt dnt u think .... that dateTimePicker1.Text & ":00" returns u something that has not in the dataGrid...

1

agree wid u ... bt i tried ur code instead of me .. that gives me some diiff out put so can u pls 1ce try my code ... nd check out whats happening ...

yes off cource , please post your code ,

take a simple windows form and put a dateTimePicker on it
and a button ...

then on button click event fill the values of day nd date in variables
like
and check the values while dubuggin...

Public Class Form1
    Protected Friend Var1 As String
    Protected Friend Var2 As String
    Protected Friend Var3 As String
    Protected Friend Var4 As String
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        Var1 = DateTimePicker1.Value.ToString("HH:mm") & ":00"
        Var2 = Now.Date.ToString("MM/dd/yyyy")
        Var3 = DateTimePicker1.Text & ":00"
        Var4 = Now.Date.ToString
    End Sub
End Class
commented: nice work :) keep it up . +5

there is both the code urs nd mine
var 1 and var 2 my code

var 3 var 4 ur code

well , i checked your code , and both are giving same value of time , as i mentioned in my previous post that please set the property of your datetimepicker from format to custom and in custom write hh:mm , but your code is much better then mines , as there is no need to set these properties when someone using your code.

Regards

hmmmm exactly ....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.