Click here to Skip to main content
15,885,309 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: .Net Core V2.2 - Sending email or gmail using OAuth2 or secure settings in Gmail in the background without browser auth Pin
Afzaal Ahmad Zeeshan1-Aug-19 14:37
professionalAfzaal Ahmad Zeeshan1-Aug-19 14:37 
GeneralRe: .Net Core V2.2 - Sending email or gmail using OAuth2 or secure settings in Gmail in the background without browser auth Pin
jkirkerx2-Aug-19 6:50
professionaljkirkerx2-Aug-19 6:50 
GeneralRe: .Net Core V2.2 - Sending email or gmail using OAuth2 or secure settings in Gmail in the background without browser auth Pin
jkirkerx2-Aug-19 11:45
professionaljkirkerx2-Aug-19 11:45 
AnswerThought I had it, Failed to open browser when running in Docker Container Pin
jkirkerx2-Aug-19 12:50
professionaljkirkerx2-Aug-19 12:50 
AnswerFigured it out [solved] Pin
jkirkerx3-Aug-19 13:44
professionaljkirkerx3-Aug-19 13:44 
GeneralRe: Figured it out [solved] - New Code Pin
jkirkerx5-Aug-19 13:22
professionaljkirkerx5-Aug-19 13:22 
QuestionInsert Date Interval Pin
Bartt_dmr25-Jul-19 10:31
Bartt_dmr25-Jul-19 10:31 
AnswerRe: Insert Date Interval Pin
Richard Deeming25-Jul-19 10:49
mveRichard Deeming25-Jul-19 10:49 
Bartt_dmr wrote:
sql = "INSERT INTO tre_Eventos (Id_Curso, DataEvento) VALUES ('" & ddlCursos.SelectedValue & "', '" & endDate & "')"

Don't do it like that!

Your code is almost certainly vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

You'll need to execute your query for each date you want to insert. Currently, you're only executing it for the end date.

Wrap your command and connection objects in Using blocks so that they're cleaned up properly.

And you should probably wrap the whole thing in a transaction - either all of the dates are inserted, or none of them are. You don't want to be in a position where the loop fails part-way through and you don't know what state your database is in.
VB.NET
Const sql As String = "INSERT INTO tre_Eventos (ID_Curso, DataEvento) VALUE (@ID_Curso, @DataEvento)"

Using conexao As New SqlConnection(strConn)
    conexao.Open()
    
    Using transaction As SqlTransaction = conexao.BeginTransaction()
        Using cmd As New SqlCommand(sql, conexao)
            cmd.Transaction = transaction
            cmd.Parameters.AddWithValue("@ID_Curso", ddlCursos.SelectedValue)
            
            Dim pDate As New SqlParameter("@DataEvento", SqlDbType.DateTime)
            cmd.Parameters.Add(pDate)
            
            Dim currDate As Date = startDate
            Do While currDate < endDate
                pDate.Value = currDate
                cmd.ExecuteNonQuery()
                currDate = currDate.AddDays(7)
            Loop
        End Using
        
        transaction.Commit()
    End Using
End Using


Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

QuestionObject reference not set to an instance of an object. Pin
Darwin Ahmed21-Jul-19 12:06
Darwin Ahmed21-Jul-19 12:06 
AnswerRe: Object reference not set to an instance of an object. Pin
phil.o21-Jul-19 19:50
professionalphil.o21-Jul-19 19:50 
AnswerRe: Object reference not set to an instance of an object. Pin
ZurdoDev24-Jul-19 9:10
professionalZurdoDev24-Jul-19 9:10 
QuestionChange Value of HttpContext.Current.User Pin
MadDashCoder21-Jul-19 4:26
MadDashCoder21-Jul-19 4:26 
AnswerRe: Change Value of HttpContext.Current.User Pin
Richard MacCutchan21-Jul-19 6:42
mveRichard MacCutchan21-Jul-19 6:42 
AnswerRe: Change Value of HttpContext.Current.User Pin
Afzaal Ahmad Zeeshan21-Jul-19 6:51
professionalAfzaal Ahmad Zeeshan21-Jul-19 6:51 
AnswerRe: Change Value of HttpContext.Current.User Pin
ZurdoDev24-Jul-19 9:12
professionalZurdoDev24-Jul-19 9:12 
QuestionQuery timing out, help please!!! Pin
samflex19-Jul-19 8:38
samflex19-Jul-19 8:38 
AnswerRe: Query timing out, help please!!! Pin
ZurdoDev19-Jul-19 10:14
professionalZurdoDev19-Jul-19 10:14 
AnswerRe: Query timing out, help please!!! Pin
David Mujica22-Jul-19 7:59
David Mujica22-Jul-19 7:59 
QuestionForm Designer Pin
wrightyrx715-Jul-19 4:58
wrightyrx715-Jul-19 4:58 
AnswerRe: Form Designer Pin
Mycroft Holmes15-Jul-19 11:26
professionalMycroft Holmes15-Jul-19 11:26 
GeneralRe: Form Designer Pin
wrightyrx715-Jul-19 11:33
wrightyrx715-Jul-19 11:33 
GeneralRe: Form Designer Pin
Mycroft Holmes15-Jul-19 14:08
professionalMycroft Holmes15-Jul-19 14:08 
QuestionGetting undefined in Cascading DropDownList In ASP.Core MVC ? Pin
Abdalla Ben Omran11-Jul-19 9:29
Abdalla Ben Omran11-Jul-19 9:29 
AnswerRe: Getting undefined in Cascading DropDownList In ASP.Core MVC ? Pin
Vincent Maverick Durano11-Jul-19 10:12
professionalVincent Maverick Durano11-Jul-19 10:12 
GeneralRe: Getting undefined in Cascading DropDownList In ASP.Core MVC ? Pin
Abdalla Ben Omran12-Jul-19 5:12
Abdalla Ben Omran12-Jul-19 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.