hi everyone, I am been trying to insert data in a table for a while now, and there is an error I keep having and I am unable to find out what I am doing wrong. here is my code:
however with that code I get the following error: The variable name '@Location' has already been declared
I don't get why I get this error. Can anyone help me figure this out?
VB.NET:
Protected Sub ButtonAjouter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonAjouter.Click
Dim oSQLConn As SqlConnection = New SqlConnection()
oSQLConn.ConnectionString = "Server=ECAMLMW091;Database=BestEffort_Dev;user=req_priority;password=********;Max Pool Size=400"
'Open the connection
Dim cmd As SqlCommand
Dim rowsAffected As Integer
Dim strSQL = "INSERT INTO tbl_Availability (Location, [Date of entry],[Date of Availability],Description,GSDC_Name,PA_Name,MGW_Name)VALUES(@Location, @DateEntry,@DateAvailability,@Description,@GSDC_Name,@PA_Name,@MGW_Name)"
'Out = File.AppendText(FILENAME)
'Connect to MSSQL Database
'Open Connection to DB if closed
If oSQLConn.State = ConnectionState.Closed Then
oSQLConn.Open()
End If
cmd = New SqlCommand(strSQL, oSQLConn)
With cmd.Parameters
.Add(New SqlParameter("@Location", SqlDbType.Char, 10))
.Add(New SqlParameter("@DateEntry", SqlDbType.DateTime, 8))
.Add(New SqlParameter("@DateAvailability", SqlDbType.Int, 4))
.Add(New SqlParameter("@Description", SqlDbType.Text, 16))
.Add(New SqlParameter("@GSDC_Name", SqlDbType.Char, 10))
.Add(New SqlParameter("@PA_Name", SqlDbType.Char, 10))
.Add(New SqlParameter("@MGW_Name", SqlDbType.Char, 10))
End With
With cmd
.Parameters.AddWithValue("@Location", DropdownLocation.Text)
.Parameters.AddWithValue("@DateEntry", Now)
.Parameters.AddWithValue("@DateAvailability", DropdownNextAvailable.Text)
.Parameters.AddWithValue("@Description", TextBoxDescription.Text)
.Parameters.AddWithValue("@GSDC_Name", DropdownGSDC.Text)
.Parameters.AddWithValue("@PA_Name", DropDownPA.Text)
.Parameters.AddWithValue("@MGW_Name", DropdownMGW.Text)
End With
Try
rowsAffected = cmd.ExecuteNonQuery()
Catch Err As Exception
Debug.WriteLine(Err.Message.ToString)
MsgBox(Err.Message.ToString)
MsgBox(strSQL)
oSQLConn.Close()
Finally
oSQLConn.Close() 'Close Connection
'Out.Close()
End Try
End Sub
however with that code I get the following error: The variable name '@Location' has already been declared
I don't get why I get this error. Can anyone help me figure this out?
Last edited: