hi i'm having a problem regarding sql deleteCommand..
can someone please help me solve this problem coz it takes a lot of time for me to figure it out..

here's my code

Private Sub btnDeleteBC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteBC.Click
        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

        da.DeleteCommand = New SqlCommand("DELETE FROM Blood_Chemistry WHERE BC_Form_ID= @BC_Form_ID", cs)



        cs.Open()
        da.DeleteCommand.ExecuteNonQuery()
        cs.Close()

        ds.Clear()
        da.Fill(ds)
    End Sub

It appears you are not setting the parameter?

how to set parameter ?

why not use a textbox to enter the id

str = "delete from blood_chemistry where BC_form_ID='" & Bc_form_id.text & "'",cs)

enter the id in textbox... Bc_form_id.text

correction

da.DeleteCommand = New SqlCommand(""delete from blood_chemistry where BC_form_ID='" & Bc_form_id.text & "'",cs)

' after Line 11
Dim param As SqlParameter = New SqlParameter("@BC_FORM_ID", SqlDbType.NVarChar, 16)
  param.Value = BC_FORM_ID.TEXT
  da.Deletecommand.parameters.Add (param)

thanks for your reply

i have seen a c# code just like this

da.DeleteCommand = New SqlCommand("DELETE FROM Blood_Chemistry WHERE BC_Form_ID= @BC_Form_ID", cs)

da.deletecommand.parameters.add("@BC_Form_ID", SqlDbType.varchar).value = ds.tables(0).rows(tablename.position)(0);

i tried this one but i got an error saying tablename is not declared

Maybe this will help, i use this when i want to delete something in the database through VB

Dim connection As New SqlClient.SqlConnection
            Dim command As New SqlClient.SqlCommand
            Dim adaptador As New SqlClient.SqlDataAdapter
            Dim dataset As New DataSet
            connection.ConnectionString = ("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Main.mdf;Integrated Security=True;User Instance=True")
            command.CommandText = "DELETE FROM VentasDD WHERE folio = " & FolioTB.Text & " ;"
            connection.Open()

            command.Connection = connection
            command.ExecuteNonQuery()
            adaptador.SelectCommand = command

but what if instead of textbox, i want to delete from a datagridview??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.