elianeasmar
Well-known member
- Joined
- Oct 3, 2013
- Messages
- 76
- Programming Experience
- Beginner
Hello again
I have this code below. it won't give me any errors. but i can't see the records in SQL.
I have this code below. it won't give me any errors. but i can't see the records in SQL.
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim strconnection As String = "Data Source=ELIANE-VAIO\SQLEXPRESS;Initial Catalog=SchoolDB;Integrated Security=True;"
Dim _cn As SqlConnection = New SqlConnection(strconnection)
_cn.Open()
Dim cmd As New SqlCommand
cmd.CommandText = "INSERT INTO StudentInfo(VB.NET:, [Full-Name], [Position], [Title], [Phone-Number], [Address], [Date-Time]) VALUES (@Code, @Name, @Position, @Title, @PhoneNumber, @Address, @DateTime);" cmd.Parameters.AddWithValue("@Code", Form1.txtCode.Text) cmd.Parameters.AddWithValue("@Name", Form1.txtName.Text) cmd.Parameters.AddWithValue("@Position", Form1.cmbPosition.Text) cmd.Parameters.AddWithValue("@Title", Form1.cmbTitle.Text) cmd.Parameters.AddWithValue("@PhoneNumber", Form1.txtPhoneNumber.Text) cmd.Parameters.AddWithValue("@Address", Form1.txtAddress.Text) cmd.Parameters.AddWithValue("@DateTime", Form1.DateTimePicker1.Value) _cn.Close() End Sub [/QUOTE] Is there anything that has to be done in order to view the newly inserted record in SQL? i can delete records with this. the record is deleted from SQL. [CODE]Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click Dim con As New SqlConnection Dim cmd As New SqlCommand Try Dim strconnection As String = "Data Source=ELIANE-VAIO\SQLEXPRESS;Initial Catalog=SchoolDB;Integrated Security=True;" Dim _cn As SqlConnection = New SqlConnection(strconnection) _cn.Open() cmd.Connection = _cn cmd.CommandText = "Delete From studentInfo where code=1" cmd.Parameters.Add(New SqlParameter("@code", 99)) cmd.ExecuteNonQuery() If MessageBox.Show("Do you really want to Delete this Record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then MsgBox("Operation Cancelled") Exit Sub End If Catch ex As Exception MessageBox.Show("Error while deleting record on table..." & ex.Message, "Delete Records") Finally con.Close() End Try End Sub
I appreciate your help
Thank you.
Lilly..