I trying to remove a row from datagridview.
it removes on datagridview but not from the database"

dataGridView1.Rows.Remove(dataGridView1.CurrentRow);

how can i remove it?

and if i have this colums in the database: AB || AC || AD || AE
and on datagridview i have only : AC || AE
can i select the value form column AB in the code?

I trying to remove a row from datagridview.
it removes on datagridview but not from the database"

dataGridView1.Rows.Remove(dataGridView1.CurrentRow);

how can i remove it?

and if i have this colums in the database: AB || AC || AD || AE
and on datagridview i have only : AC || AE
can i select the value form column AB in the code?

hey to remove it from the database you have to write a SQL query with the delete command

hope you got it
thankxxx

If the data is stored in a dataset (filled using DataAdapter.Fill) then you can also use the DataAdapter.Update method to delete the removed records.
This will also update any changed records and add any new records to the DB.

If the data is stored in a dataset (filled using DataAdapter.Fill) then you can also use the DataAdapter.Update method to delete the removed records.
This will also update any changed records and add any new records to the DB.

i get a error that i have not a falid deleteCommand.

dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
            this.bonRegelsTableAdapter.Adapter.Update(this.dataKassaDataSet.bonRegels);

wat do i wrong?

In the dataset designer click on the bonRegelsTableAdapter.
What do you have in DeleteCommand.CommandText?
It should be a suitable SQL command to perform a delete.

In the dataset designer click on the bonRegelsTableAdapter.
What do you have in DeleteCommand.CommandText?
It should be a suitable SQL command to perform a delete.

i have there nothing.

what can i write there?

DELETE FROM BonRegels where id = ???

You should add a delete command using parameters.
The following is and example from one of my tableadapters.

DELETE FROM Channels WHERE (ID = @Original_ID) AND (Date = @Original_Date) AND (LogIntervals = @Original_LogIntervals)

You will need to modify the field names to match your table. Note: Only include fields that have a fixed field size (i.e. not varchar(MAX) or nvarchar(MAX)).
Also you need to add the parameters in the parameters collection.
These are named @Original_ID, @Original_Date, @Original_LogIntervals in my example.
The parameter types need to match what is in your table.

You should also check the Insert and Update command.
These are examples from my tableadapter.

INSERT INTO [dbo].[Channels] ([Date], [Names], [Settings], [LogIntervals]) VALUES (@Date, @Names, @Settings, @LogIntervals);
SELECT ID, Date, Names, Settings, LogIntervals FROM Channels WHERE (ID = SCOPE_IDENTITY())
UPDATE [dbo].[Channels] SET [Date] = @Date, [Names] = @Names, [Settings] = @Settings, [LogIntervals] = @LogIntervals WHERE (([ID] = @Original_ID) AND ([Date] = @Original_Date) AND ([LogIntervals] = @Original_LogIntervals));
SELECT ID, Date, Names, Settings, LogIntervals FROM Channels WHERE (ID = @ID)

dataGridView1.Rows.RemoveAt(i);


sasanka

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.