Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hey I have have created a store procedure in SQL for deleting a data from my data base the store procedure is working fine when I am using it in SQL but when I call same store procedure in my VB.Net project here I am getting msg data deleted but when checking physically data still remains in data base . Can any one help.
The Store procedure is
SQL
create proc  sptblTrg_detail_Delete
@Course_Id int
as
begin
delete tblTrg_Detail where Trg_Ind_ID= @Course_Id
End


And VB.Net code
VB
Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
       Gp1.Enabled = True
       If TxtPIS.Text = "" Then
           MsgBox("Please Enter PIS No and Correct Batch NO")
           TxtPIS.Focus()
           Exit Sub
       Else
           Dim Mycon As New SqlConnection(con)
           Mycon.Open()
           Dim da As SqlDataAdapter
           da = New SqlDataAdapter("sptblTrg_detail_Delete", Mycon)
           da.SelectCommand.CommandType = CommandType.StoredProcedure
           da.SelectCommand.Parameters.AddWithValue("@Course_Id", TxtCourseID.Text)
           MsgBox("Detail Deleted Successfully")
           clearall()
           Dgvtrainees.DataSource = Nothing
       End If
   End Sub
Posted
Updated 17-Jun-14 18:29pm
v2
Comments
Thava Rajan 18-Jun-14 2:16am    
there are lot of problems here use the Normal command

This is what you need i think
VB
Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
    If TxtPIS.Text = "" Then
        MsgBox("Please Enter PIS No and Correct Batch NO")
        TxtPIS.Focus()
        Exit Sub
    Else
        Dim con As String, RecordsAffected As Integer
        Try
            Using Mycon As New SqlConnection(con)
                Mycon.Open()
                Using cmd As New SqlCommand("sptblTrg_detail_Delete", Mycon)
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Parameters.AddWithValue("@Course_Id", TxtCourseID.Text)
                    RecordsAffected = cmd.ExecuteNonQuery()
                End Using
            End Using
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            If RecordsAffected > 0 Then
                MessageBox.Show("Detail Deleted Successfully")
                clearall()
                Dgvtrainees.DataSource = Nothing
            Else
                MessageBox.Show("Problem in Deleting")
            End If
        End Try
    End If
End Sub
 
Share this answer
 
Hi Ram,

You have not written statement to execute stored procedure...
 
Share this answer
 
try this.. :)
1) You have not erote from in stored procedure.

SQL
create proc  sptblTrg_detail_Delete
@Course_Id int
as
begin
delete from tblTrg_Detail where Trg_Ind_ID= @Course_Id
End


2) There is no need to use Sqldataadapter for delete records in database you can use ExecuteNonQuery inseated it
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900