Results 1 to 11 of 11

Thread: [RESOLVED] INSERT INTO using SqlConnection and SqlCommand

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2017
    Posts
    165

    Resolved [RESOLVED] INSERT INTO using SqlConnection and SqlCommand

    I have a Database with a Table named Orders and a column OrderNo. In a Form with a textbox ctlOrder I write the OrderNo value. This is the code:

    Code:
    Dim theText As String
            theText = ctlOrder.Text
            Dim CNstring As String = "Data Source=EBELLO-PC\SQLEXPRESS;Initial " &
                "Catalog=Orders;Integrated Security=True"
            If CNstring.Trim = "" Then Exit Sub
            Dim CN As New SqlConnection(CNstring)
            Dim cmd As SqlCommand = New SqlCommand()
            cmd.CommandText = "INSERT INTO Orders(OrderNo) VALUES ('theText')"
            cmd.Connection = CN
            CN.Open()
            cmd.ExecuteNonQuery()
    When I open the Table Orders in the field OrderNo the value is the word theText instead of the value.
    Last edited by ebellounisoft; May 20th, 2018 at 07:56 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width