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. UPDATE and DELETE in VB.NET

UPDATE and DELETE in VB.NET

Scheduled Pinned Locked Moved Visual Basic
databasecsharptutorialannouncement
3 Posts 2 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.
  • L Offline
    L Offline
    lis8586
    wrote on last edited by
    #1

    :(( HI All, I have a simple program where I insert values into a Sql Database. The following is my INSERT code: Public SqlConn As New SqlConnection() Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click SqlConn = New SqlConnection("Data Source=SOORAJ;Initial Catalog=TrackEmp;User Id=sa; Password=; ") Dim cmdText As String = "INSERT into EmpMaster(Name, Age, Gender, Address, TelephoneNo, MaritalStatus, Salary, Post,Department) Values ('" & txtName.Text & "','" & txtAge.Text & "','" & gSex & "', '" & txtAddress.Text & "', '" & txtPhone.Text & "','" & mStatus & "', '" & txtSalary.Text & "','" & txtDesignation.Text & "', '" & txtDept.Text & "')" SqlConn.Open() Dim cm As New SqlCommand(cmdText, SqlConn) cm.ExecuteNonQuery() SqlConn.Close() MsgBox(" The Employee has been Added") txtName.Text = "" txtAge.Text = "" txtAddress.Text = "" txtPhone.Text = "" txtSalary.Text = "" txtDesignation.Text = "" txtDept.Text = "" End Sub, I have 3 tables in my Database. Can someone tell me how to go about with the UPDATE And DELETE. Thanks and Regards, lis Thinking is like loving and dying. Each of us must do it for himself.

    M 1 Reply Last reply
    0
    • L lis8586

      :(( HI All, I have a simple program where I insert values into a Sql Database. The following is my INSERT code: Public SqlConn As New SqlConnection() Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click SqlConn = New SqlConnection("Data Source=SOORAJ;Initial Catalog=TrackEmp;User Id=sa; Password=; ") Dim cmdText As String = "INSERT into EmpMaster(Name, Age, Gender, Address, TelephoneNo, MaritalStatus, Salary, Post,Department) Values ('" & txtName.Text & "','" & txtAge.Text & "','" & gSex & "', '" & txtAddress.Text & "', '" & txtPhone.Text & "','" & mStatus & "', '" & txtSalary.Text & "','" & txtDesignation.Text & "', '" & txtDept.Text & "')" SqlConn.Open() Dim cm As New SqlCommand(cmdText, SqlConn) cm.ExecuteNonQuery() SqlConn.Close() MsgBox(" The Employee has been Added") txtName.Text = "" txtAge.Text = "" txtAddress.Text = "" txtPhone.Text = "" txtSalary.Text = "" txtDesignation.Text = "" txtDept.Text = "" End Sub, I have 3 tables in my Database. Can someone tell me how to go about with the UPDATE And DELETE. Thanks and Regards, lis Thinking is like loving and dying. Each of us must do it for himself.

      M Offline
      M Offline
      MohammadAmiry
      wrote on last edited by
      #2

      DELETE Statement[^] You can find UPDATE Statement from the same site.

      L 1 Reply Last reply
      0
      • M MohammadAmiry

        DELETE Statement[^] You can find UPDATE Statement from the same site.

        L Offline
        L Offline
        lis8586
        wrote on last edited by
        #3

        Hi, It is not the statement I want but that my following code is giving me error.: **Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click SqlConn = New SqlConnection("Data Source=SOORAJ;Initial Catalog=TrackEmp;User Id=sa;Password=; ") Dim cmdText As String = "DELETE FROM EmpMaster where [Name] ='" & txtName.Text & "'" SqlConn.Open() Dim cm As New SqlCommand(cmdText, SqlConn) cm.ExecuteNonQuery() SqlConn.Close() MsgBox(" The Record has been Deleted") End Sub** This is the error it is giving me An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional information: System error. Can someone tell me where I am going wrong?? thanks and regards, lis :confused: Thinking is like loving and dying. Each of us must do it for himself.

        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