-1
Try
        con.Open()
        sql = "INSERT INTO into Services(Service Name,Service Cost,Description)values('" & txtname.Text & "'," & Val(txtcost.Text) & "," & txtdes.Text & ")"
        cmd.Connection = con
        cmd.CommandText = Sql
        i = cmd.ExecuteNonQuery
          If i > 0 Then
            MsgBox("New record has been inserted successfully!")
        Else
            MsgBox("No record has been inserted successfully!")
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        con.Close()
    End Try
Scott Hunter
  • 48,888
  • 12
  • 60
  • 101

2 Answers2

0

Try with:

sql = "Insert Into Services ([Service Name], [Service Cost], [Description]) Values('" & txtname.Text & "'," & txtcost.Text & ",'" & txtdes.Text & "')"
    
Gustav
  • 53,498
  • 7
  • 29
  • 55
  • 1
    While I agree you've technically answered the question, wouldn't it be a far more robust solution to show usage of parameters? – Hursey Jul 26 '22 at 00:01
  • @Hursey: Yes, but I didn't have the time. Many examples and tutorials can be looked up. – Gustav Jul 26 '22 at 08:38
0

You have to learn how to create table names and table columns first, if you give space in table columns then need to use square bracket in all queries, instead of space why cant use underscore "_" between two words ?

Two ways to solve your problem.

  1. [Service Name], [Service Cost] .... give square bracket or
  2. Service_Name, Service_Cost .... give underscore between two words in table columns in table design and no need to give square bracket in all SQL statement.

And one more thing always use command with parameters in all SQL statement.

From your stackoverflow name i thing your are now schooling so starting onwards change the way.

Aravind Aravind
  • 179
  • 1
  • 10