I have an insert statement in my VB code that updates about 20 fields in sql. I pass through todays date and a set of values.
This occurs on a button click event. My problem is if the button is clicked more than once the data is duplicated in the sql table, ie there is two rows of data for the same date. Is there anyway for it to overwrite the current data if the date is the same but put a new row in if it is a different date?
Below is an example of the code
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
Using selectCommand As SqlCommand = conn.CreateCommand
.CommandType = CommandType.Text
.CommandText = "INSERT INTO dbo.MorningReport(--Fields--) " + "VALUES--@fields--)"
.Parameters.Add("@field1", SqlDbType.DateTime).Value = Date.Now
.Parameters.Add("@field2", SqlDbType.Int).Value = getavgNT()