Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. I need some hints about sqlcommand

I need some hints about sqlcommand

Scheduled Pinned Locked Moved Visual Basic
helpdatabasesql-serversysadminannouncement
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    y_mmohd
    wrote on last edited by
    #1

    :confused: I'm trying to pass and retrieve data from textbox to sql server. I want to insert, delete, update, select from a table I write the following code. Can you help me for What I miss: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try sqlconn.Open() 'Insert command sqlstr = TextBox1.Text sqlcomm = New SqlCommand("insert into mytable name values sqlstr", sqlconn) TextBox2.Text = ("New Record inserted into Mytable table in pubs.") Catch MessageBox.Show("The Connection could not be opened!", "Error message !", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally sqlconn.Close() End Try End Sub Thanks

    D Y 2 Replies Last reply
    0
    • Y y_mmohd

      :confused: I'm trying to pass and retrieve data from textbox to sql server. I want to insert, delete, update, select from a table I write the following code. Can you help me for What I miss: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try sqlconn.Open() 'Insert command sqlstr = TextBox1.Text sqlcomm = New SqlCommand("insert into mytable name values sqlstr", sqlconn) TextBox2.Text = ("New Record inserted into Mytable table in pubs.") Catch MessageBox.Show("The Connection could not be opened!", "Error message !", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally sqlconn.Close() End Try End Sub Thanks

      D Offline
      D Offline
      dptalt
      wrote on last edited by
      #2

      Add this line sqlcomm.ExecuteNonQuery() after this line sqlcomm = New SqlCommand("insert into mytable name values sqlstr", sqlconn)

      Y 1 Reply Last reply
      0
      • D dptalt

        Add this line sqlcomm.ExecuteNonQuery() after this line sqlcomm = New SqlCommand("insert into mytable name values sqlstr", sqlconn)

        Y Offline
        Y Offline
        y_mmohd
        wrote on last edited by
        #3

        Thanks for help: When I add sqlcomm.executenonquery() the code moves to catch and run the error message. Any Explanation about this please. Thanks

        C 1 Reply Last reply
        0
        • Y y_mmohd

          Thanks for help: When I add sqlcomm.executenonquery() the code moves to catch and run the error message. Any Explanation about this please. Thanks

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          y_mmohd wrote:

          the code moves to catch and run the error message. Any Explanation about this please.

          Ask your application. It knows what the error was, but you don't ever find out. Catch ex as SqlException now, ex will contain the details of the error (ex.Message will give you a reason) - it probably isn't to do with the connection, so your existing error message is misleading.


          My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

          1 Reply Last reply
          0
          • Y y_mmohd

            :confused: I'm trying to pass and retrieve data from textbox to sql server. I want to insert, delete, update, select from a table I write the following code. Can you help me for What I miss: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try sqlconn.Open() 'Insert command sqlstr = TextBox1.Text sqlcomm = New SqlCommand("insert into mytable name values sqlstr", sqlconn) TextBox2.Text = ("New Record inserted into Mytable table in pubs.") Catch MessageBox.Show("The Connection could not be opened!", "Error message !", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally sqlconn.Close() End Try End Sub Thanks

            Y Offline
            Y Offline
            y_mmohd
            wrote on last edited by
            #5

            Its Done, Thanks for Help :-D I need a to send string and retreive string to sql table using sql command. I write: sqlcomm = new sqlcomman (insert into mytable (name) values ('string'),sqlconn) Bu How can i do this using a textbox, I miss understand the syntax. Thanks

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups