Question Update and Delet Statement

ryanescal

Member
Joined
Sep 24, 2011
Messages
7
Programming Experience
3-5
Hi Everyone
I have a problem about the update and delete statements without error but I turnwhen I update or delete data, but does not occur
this is my code for Delete
Dim conn As New SqlConnection
Dim cmd As New SqlCommand
Dim str As String
With conn
.ConnectionString = "Data Source=RYAN-PC\RYAN;Initial Catalog=DRRM_Student_Database;User ID=sa;Password=12345"
.Open()
End With
With cmd.Parameters
.Add(New SqlParameter("@Id", txtid.Text))
End With
str = "delete from DRRM_HonorableDismissal_Database where Id = @Id"
cmd.CommandText = str
cmd.Connection = conn
cmd.ExecuteNonQuery()

Update Code:
With cmd.Parameters
.Add(New SqlParameter("@Id", lblid.Text))
.Add(New SqlParameter("@LastName", txtlastname.Text))
.Add(New SqlParameter("@FirstName", txtfirstname.Text))
.Add(New SqlParameter("@MiddleName", txtmiddlename.Text))
.Add(New SqlParameter("@StudentNo", txtstudentno.Text))
.Add(New SqlParameter("@SoNo", txtsono.Text))
.Add(New SqlParameter("@Address", txtaddress.Text))
.Add(New SqlParameter("@ContactNo", txtcontact.Text))
.Add(New SqlParameter("@Major", txtmajor.Text))
.Add(New SqlParameter("@HighSchoolGraduate", txthsgraduate.Text))
.Add(New SqlParameter("@YearGraduate", txtyeargraduate.Text))
.Add(New SqlParameter("@DateApplied", txtdateapplied.Text))
.Add(New SqlParameter("@DateRealese", txtdaterealesed.Text))
.Add(New SqlParameter("@Copy", txtcopy.Text))
.Add(New SqlParameter("@Notes", txtnotes.Text))
End With
Dim response = MessageBox.Show("Update this Data?.", "DRRM Monitoring and Transaction Sys.", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If response = vbYes Then
Try
Dim str = "UPDATE TranscriptofRecordsGraduate SET " & _
"LastName = @LastName, " & _
"FirstName = @FirstName, " & _
"MiddleName = @MiddleName, " & _
"StudentNo = @StudentNo, " & _
"SoNo = @SoNo, " & _
"Address = @Address, " & _
"ContactNo = @ContactNo, " & _
"Major = @Major, " & _
"HighSchoolGraduate = @HighSchoolGraduate, " & _
"YearGraduate = @YearGraduate, " & _
"DateApplied = @DateApplied, " & _
"DateRealese = @DateRealese, " & _
"Copy = @Copy, " & _
"Notes = @Notes " & _
"where Id = @Id "
cmd.Connection = conn
cmd.CommandText = str
cmd.ExecuteNonQuery()
MessageBox.Show("Update success")
Me.dataview()
 
Have you thought about using a stored procedure? Then you can just call the procedure (similar to how you currently do it) but just send it the vars, so you don't need to build that huge string at the end?
 
Back
Top