-
Jul 29th, 2020, 05:52 AM
#1
Thread Starter
New Member
How can I set an event using the data from a SQL database
Hi all
I have written simple programs that show in DataGridView some info. The most important info is the expiration date , which I manage to color it read when the expiration date is near(like 5 days). The person responsible has an email in the database. I use a SQL database. What is the code to send email only to the persons that their products are near the expiration date? If I call the function send_mail() in the code that colors the line red it sends infinite mails to 1 person. This is my code:
Private Sub dgvExcel_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
If CDate(DataGridView1.Rows(e.RowIndex).Cells(DataGridView1.Columns(5).Index).Value) <= Date.Now Then
e.CellStyle.BackColor = Color.Red
'send_mail()
End If
If CDate(DataGridView1.Rows(e.RowIndex).Cells(DataGridView1.Columns(4).Index).Value) <= Date.Now Then
e.CellStyle.BackColor = Color.White
e.CellStyle.ForeColor = Color.Black
End If
End Sub
-
Jul 29th, 2020, 06:19 AM
#2
Re: How can I set an event using the data from a SQL database
So what does send_mail() look like? if that is responsible for sending the emails then there is a good chance that is where the problem lies.
Last edited by PlausiblyDamp; Jul 29th, 2020 at 09:21 AM.
-
Jul 29th, 2020, 09:08 AM
#3
Re: How can I set an event using the data from a SQL database
That's because you're calling it from the CellFormatting event... which is not the appropriate place to call it... or it might be... but you only want to call it once... not every single time. Do you even want to send them an email? They're already in the app. They can see the row/cell in red... Is sending them an email from inside the app telling them something they should already know really what you want?
A more appropriate (in my opinion) method for sending the emails would be for a SQL Server job to scan the table, and send the emails once a day, so that it alerts them at the beginning of the day that these are the ones to watch for. But that's the server/database doing it, not the app, and is a different thing alltogeher.
-tg
-
Jul 29th, 2020, 11:29 AM
#4
Re: How can I set an event using the data from a SQL database
I like that approach. If they run the app, the email is redundant. If they don't run the app, the email will never happen. An email that is separate from the app seems more likely to be useful...with a few caveats. If the database is on their local computer, then I'd say that no email is ever appropriate, because there are better options, but I'm thinking that's not the case.
My usual boring signature: Nothing
-
Aug 3rd, 2020, 12:42 PM
#5
Thread Starter
New Member
Re: How can I set an event using the data from a SQL database
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|