UPDATE and DELETE in VB.NET
-
:(( 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. -
:(( 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.DELETE Statement[^] You can find UPDATE Statement from the same site.
-
DELETE Statement[^] You can find UPDATE Statement from the same site.
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.