I developed an application for registration of Transport Clients linked to an "MDF" database, trying to save to the database gives the error:
"Incorrect syntax near '-'"
I have tried everything, changed the codes, changed several things but the error prevails.
Codes:
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Try
con = New SqlConnection(cs)
con.Open()
Dim ct As String = "select id from Clientes where id='" & IdTextBox.Text & "'"
cmd = New SqlCommand(ct)
cmd.Connection = con
rdr = cmd.ExecuteReader()
If rdr.Read() Then
MessageBox.Show("Id ja existe", "Erro", MessageBoxButtons.OK, MessageBoxIcon.[Error])
IdTextBox.Text = ""
IdTextBox.Focus()
If (rdr IsNot Nothing) Then
rdr.Close()
End If
Return
End If
con = New SqlConnection(cs)
con.Open()
Dim cb As String = "insert into Clientes(id, nome, cidade, matricula, marca, lotacao, partida, chegada, capacidade, estado, Tipo-Licenca, Licenca-emissao, licenca-expira, seguros-emissao, seguros-expira, ficha-emissao, ficha-expira, data-registado) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17,@d18)"
cmd = New SqlCommand(cb)
cmd.Connection = con
cmd.Parameters.AddWithValue("@d1", IdTextBox.Text)
cmd.Parameters.AddWithValue("@d2", NomeTextBox.Text)
cmd.Parameters.AddWithValue("@d3", CidadeComboBox.Text)
cmd.Parameters.AddWithValue("@d4", MatriculaTextBox.Text)
cmd.Parameters.AddWithValue("@d5", MarcaComboBox.Text)
cmd.Parameters.AddWithValue("@d6", LotacaoComboBox.Text)
cmd.Parameters.AddWithValue("@d7", PartidaComboBox.Text)
cmd.Parameters.AddWithValue("@d8", ChegadaComboBox.Text)
cmd.Parameters.AddWithValue("@d9", CapacidadeComboBox.Text)
cmd.Parameters.AddWithValue("@d10", EstadoComboBox.Text)
cmd.Parameters.AddWithValue("@d11", Tipo_LicencaComboBox.Text)
cmd.Parameters.AddWithValue("@d12", Licenca_emissaoDateTimePicker.Text)
cmd.Parameters.AddWithValue("@d13", Licenca_ExpiraDateTimePicker.Text)
cmd.Parameters.AddWithValue("@d14", Seguros_EmissaoDateTimePicker.Text)
cmd.Parameters.AddWithValue("@d15", Seguros_ExpiraDateTimePicker.Text)
cmd.Parameters.AddWithValue("@d16", Ficha_EmissaoDateTimePicker.Text)
cmd.Parameters.AddWithValue("@d17", Ficha_ExpiraDateTimePicker.Text)
cmd.Parameters.AddWithValue("@d18", Now)
cmd.ExecuteReader()
con.Close()
MessageBox.Show("Cliente registado com sucesso", "Cliente", MessageBoxButtons.OK, MessageBoxIcon.Information)
btnSave.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End Try
End Sub
Note: The Customers form has ComboBox's that pull data from other tables: Example: The ComboBox 'ComboBox Capacity' pulls the data from the 'Capacity' table