سؤال

Firstly, I checked this page but It doesn't seem to help me.

I'm using this edmx file.

Here is my code sample:

private void btnSil_Click(object sender, EventArgs e)
    {
        Int64 isbn = Int64.Parse(dgvKitaplar.CurrentRow.Cells["ISBN"].Value.ToString());

        entity.sp_Sil(isbn);

        entity.SaveChanges();

        dgvKitaplar.DataSource = entity.sp_Update();


    }

Here is my sp_Update() stored procedure

create proc [dbo].[sp_Sil]
        @toDeleteBookId bigint
        as

        begin
        delete from BookInfo
        where ISBN=@toDeleteBookId
        end

What I'm trying to do is deleting a book from the library database via datagridview's current row. First of all, if there is a better/more secure way to do this, I would like to know.

Why am I getting "EntityCommandExecutionException was unhandled"? I know it's quite easy but I'm trying to learn c# and .net environment.
Thanks in advance.

@I guess it's because of something about data tables but I still can't find what it is.

هل كانت مفيدة؟

المحلول

If the data model says its a "one to one" between BookInfo and Book, then you will not be able to delete the BookInfo without deleting the Book.

To solve this, update the data model to be "zero to one". Then you should be able to delete the BookInfo. HTH.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top