Hello. I started making my software and i using database. When I select record in database and click Delete Button i got error message: Update requires a valid DeleteCommand when passed DataRow collection with deleted rows. The code of my Delete Button is:

Private Sub DeleteMember_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteMember.Click
        If MsgBox("Da li ste sigurni da želite da izbrišete člana?", MsgBoxStyle.YesNo, Title:="Operacija brisanja člana") = vbYes Then
            Me.Table1BindingSource.RemoveCurrent()
            Me.Validate()
            Me.Table1BindingSource.EndEdit()
            Me.TableAdapterManager1.UpdateAll(Me.Database1DataSet)
            GroupBox1.Enabled = False
            GroupBox2.Enabled = False
        Else

        End If
    End Sub

Only what I need is a valid DeleteCommand that delete records I deleted with Delete Button. Can anyone help me? And before helping me tell me is that possible. Thanks

You need to specify the Delete command for your DataAdapter - you can do this inside your delete button or when you set it up.

Another option is to run a SQL command with a delete statement.

Your DataAdapter does not magically know how to delete data from the database.

es not magically know how to delete dat

I know but I first time working with Database and I don't know how to build valid DeleteCommand. My columns are: ID, FirstName, Lastname, Type, Phone, Books. If you know how to build valid DeleteCommand please help me with it. Just give me text of this command if you can. No problem if you can't but you are first man from this forum who can help me.

Thanks.

Hope this will help you

        Dim check As Integer

        Dim cmdStudent As New SqlCommand
        Dim daStudent As New SqlDataAdapter
        Dim dsStudent As New DataSet
        myConnection = New SqlConnection(Module1.connectionString)
        myConnection.Open()


        cmdStudent = myConnection.CreateCommand
        cmdStudent.CommandText = "DELETE FROM  Major WHERE MajorName ='" & Trim(TextBox1.Text) & "'"
        check = cmdStudent.ExecuteReader.RecordsAffected
        If check > 0 Then
            MsgBox("Student With MajorName " & Trim(TextBox1.Text) & " Succesfully To Delete", MsgBoxStyle.OkOnly, "Info Delete Student")
        Else
            MsgBox("Student With MajorName " & Trim(TextBox1.Text) & " Failure To Delete", MsgBoxStyle.OkOnly, "Info Delete Student")
        End If
        refreshComponents()

Hmm.. Can i get DeleteCommand from Properties in TableAdapter? I don't want any code, DeleteCommand is all what I want. I know:

DELETE FROM Table1
WHERE ID = <someID>

but i want

DELETE FROM Table1
WHERE ID = <Rows that I removed with Delete Button>

I taught you want read the entire row .if so you can by using my coding
I have heard Calling table adapter.......

I taught you want read the entire row .if so you can by using my coding
I have heard Calling table adapter.......

Properties of Table1TableAdapter are:

BaseClass...System.ComponentModel.Component
Connection...Database1ConnectionString (MySettings)
    Name...Database1ConnectionString (MySettings)
    Modifier...Friend
    ConnectionString...Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database\Database1.mdf;Integrated Security=True;User Instance=True
ConnectionModifier...Friend
DeleteCommand...None
GenerateDBDirectMethods...True
InsertCommand...(InsertCommand)
    CommandText...INSERT INTO [dbo].[Table1] ([ID], [Ime], [Prezime], [Razred], [Telefon], [Knjiga]) VALUES (@ID, @Ime, @Prezime, @Razred, @Telefon, @Knjiga)
    Parameters...(Collections)
Modifier...Public
Name...Table1TableAdapter
SelectCommand...(SelectCommand)
    CommandText...SELECT ID, Ime, Prezime, Razred, Telefon, Knjiga FROM dbo.Table1
    CommandType...Text
    Parameters...(Collection)
UpdateCommand...None

If you have time, fix it if you understand what I want.

Thanks.

LD COmpany after going though your codes I think the delete command should be like this .......

DeleteCommand...(DeleteCommand)
CommandText...Delete ID, Ime, Prezime, Razred, Telefon, Knjiga FROM dbo.Table1 WHERE ID=@ID
CommandType...Text
Parameters...(Collection)

When I enter this command and click ok button in Query Builder I get error message:Error in table name or view name in DELETE clause.
Unable to parse query text.
and buttons UNDO and IGNORE

Are you using Sql
if you don't have put dbo.Table1 insted you put only the table name
What is UnDo and IGNore i can't understand it

if you don't have put dbo.Table1 insted you put only the table name
What is UnDo and IGNore i can't understand it

I know only about 20% about databases. This is my first database project. I think I using SQL but I don't know anything about it. I am just newbie with databases.

Okay even i'm not a genius i tried to help you with, coding which i used in a my application
what is the database or software package, you linked to your vb application
from where did you found this coding,did wrote by your self?
because this the way i used to do connect database to the application in SQL 2005

Public connectionString As String = "Data Source=HP-PC;Initial Catalog=Vb_table;user ID =sa; password= 1234"

i 'm really sorry if this is not helpful to you.......... i know very little

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.