Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

In VB.NET 14 (for VS2015) you can use String interpolation and make your code a lot cleaner (For Reference For Reference)

you could write the loop, that Mat's Mug talks about, like this:

For month = 1 To 12
 cmd = New OleDbCommand(sql, con, trans)
 cmd.Parameters.Add("@period", OleDbType.VarChar).Value = $"{month:D2}{period}"
 cmd.Parameters.Add("@month", OleDbType.Integer).Value = month
 cmd.Parameters.Add("@year", OleDbType.Integer).Value = nextyear
 cmd.ExecuteNonQuery()
Next

With String Interpolation (in VB and C# at least) you can include your formatting in the variable call using the Colon just like you would in a string.format method call. This is really the exact same thing as using the String.Format except shorter.

In VB.NET 14 (for VS2015) you can use String interpolation and make your code a lot cleaner (For Reference)

you could write the loop, that Mat's Mug talks about, like this:

For month = 1 To 12
 cmd = New OleDbCommand(sql, con, trans)
 cmd.Parameters.Add("@period", OleDbType.VarChar).Value = $"{month:D2}{period}"
 cmd.Parameters.Add("@month", OleDbType.Integer).Value = month
 cmd.Parameters.Add("@year", OleDbType.Integer).Value = nextyear
 cmd.ExecuteNonQuery()
Next

With String Interpolation (in VB and C# at least) you can include your formatting in the variable call using the Colon just like you would in a string.format method call. This is really the exact same thing as using the String.Format except shorter.

In VB.NET 14 (for VS2015) you can use String interpolation and make your code a lot cleaner (For Reference)

you could write the loop, that Mat's Mug talks about, like this:

For month = 1 To 12
 cmd = New OleDbCommand(sql, con, trans)
 cmd.Parameters.Add("@period", OleDbType.VarChar).Value = $"{month:D2}{period}"
 cmd.Parameters.Add("@month", OleDbType.Integer).Value = month
 cmd.Parameters.Add("@year", OleDbType.Integer).Value = nextyear
 cmd.ExecuteNonQuery()
Next

With String Interpolation (in VB and C# at least) you can include your formatting in the variable call using the Colon just like you would in a string.format method call. This is really the exact same thing as using the String.Format except shorter.

added 254 characters in body
Source Link
Malachi
  • 29k
  • 11
  • 86
  • 188

In VB.NET 14 (for VS2015) you can use String interpolation and make your code a lot cleaner (For Reference)

you could write the loop, that Mat's Mug talks about, like this:

For month = 1 To 12
 cmd = New OleDbCommand(sql, con, trans)
 cmd.Parameters.Add("@period", OleDbType.VarChar).Value = $"{month:D2}{period}"
 cmd.Parameters.Add("@month", OleDbType.Integer).Value = month
 cmd.Parameters.Add("@year", OleDbType.Integer).Value = nextyear
 cmd.ExecuteNonQuery()
Next

With String Interpolation (in VB and C# at least) you can include your formatting in the variable call using the Colon just like you would in a string.format method call. This is really the exact same thing as using the String.Format except shorter.

In VB.NET 14 (for VS2015) you can use String interpolation and make your code a lot cleaner (For Reference)

you could write the loop, that Mat's Mug talks about, like this:

For month = 1 To 12
 cmd = New OleDbCommand(sql, con, trans)
 cmd.Parameters.Add("@period", OleDbType.VarChar).Value = $"{month:D2}{period}"
 cmd.Parameters.Add("@month", OleDbType.Integer).Value = month
 cmd.Parameters.Add("@year", OleDbType.Integer).Value = nextyear
 cmd.ExecuteNonQuery()
Next

In VB.NET 14 (for VS2015) you can use String interpolation and make your code a lot cleaner (For Reference)

you could write the loop, that Mat's Mug talks about, like this:

For month = 1 To 12
 cmd = New OleDbCommand(sql, con, trans)
 cmd.Parameters.Add("@period", OleDbType.VarChar).Value = $"{month:D2}{period}"
 cmd.Parameters.Add("@month", OleDbType.Integer).Value = month
 cmd.Parameters.Add("@year", OleDbType.Integer).Value = nextyear
 cmd.ExecuteNonQuery()
Next

With String Interpolation (in VB and C# at least) you can include your formatting in the variable call using the Colon just like you would in a string.format method call. This is really the exact same thing as using the String.Format except shorter.

changed the loop to include Parameters
Source Link
Malachi
  • 29k
  • 11
  • 86
  • 188

In VB.NET 14 (for VS2015) you can use String interpolation and make your code a lot cleaner (For Reference)

you could write the loop, that Mat's Mug talks about, like this:

For imonth = 1 To 12
 sqlCommandStringcmd = $"UPDATENew [periods]OleDbCommand(sql, SETcon, [period]trans)
  cmd.Parameters.Add("@period", OleDbType.VarChar).Value = '$"{imonth:D2}{period}'"
 WHERE [month] = {i} ANDcmd.Parameters.Add("@month", [year]OleDbType.Integer).Value = {nextyear}"month
 cmd = New OleDbCommand.Parameters.Add(sqlCommandString, con"@year", transOleDbType.Integer).Value = nextyear
 cmd.ExecuteNonQuery()
Next

This way you don't have to add all those parameters to the cmd before you execute the code.

I will caution you that if you are filling any variable through a user input, this ceases to be a good idea.

If you were doing anything with user input, I would tell you to create a stored procedure and send the input to the stored procedure as parameters so that the application and the database know not to execute the input.

In VB.NET 14 (for VS2015) you can use String interpolation and make your code a lot cleaner (For Reference)

you could write the loop, that Mat's Mug talks about, like this:

For i = 1 To 12
 sqlCommandString = $"UPDATE [periods] SET [period] = '{i:D2}{period}' WHERE [month] = {i} AND [year] = {nextyear}"
 cmd = New OleDbCommand(sqlCommandString, con, trans)
 cmd.ExecuteNonQuery()
Next

This way you don't have to add all those parameters to the cmd before you execute the code.

I will caution you that if you are filling any variable through a user input, this ceases to be a good idea.

If you were doing anything with user input, I would tell you to create a stored procedure and send the input to the stored procedure as parameters so that the application and the database know not to execute the input.

In VB.NET 14 (for VS2015) you can use String interpolation and make your code a lot cleaner (For Reference)

you could write the loop, that Mat's Mug talks about, like this:

For month = 1 To 12
 cmd = New OleDbCommand(sql, con, trans)
  cmd.Parameters.Add("@period", OleDbType.VarChar).Value = $"{month:D2}{period}"
 cmd.Parameters.Add("@month", OleDbType.Integer).Value = month
 cmd.Parameters.Add("@year", OleDbType.Integer).Value = nextyear
 cmd.ExecuteNonQuery()
Next
added 2 characters in body
Source Link
Malachi
  • 29k
  • 11
  • 86
  • 188
Loading
Source Link
Malachi
  • 29k
  • 11
  • 86
  • 188
Loading
default

AltStyle によって変換されたページ (->オリジナル) /