locked
Delete button code using checkbox RRS feed

  • Question

  • User-256597427 posted

    // Delete Button Details//
    private void button3_Click(object sender, EventArgs e)
    {
    iselibraryEntities ise = new iselibraryEntities();
    foreach(var item in dataGridView1.Rows)
    {
    DataGridViewRow row = item as DataGridViewRow;
    if(row.Selected)
    {
    string usn = row.Cells["USN"].Value.ToString();
    var issu = ise.T_BOOK_ISSUE_TABLE.FirstOrDefault(a => a.USN.Equals(usn));
    if(issu!=null)
    {
    ise.T_BOOK_ISSUE_TABLE.Remove

    }
    }
    Thing is I don't get a dropdown for remove in if loop after ise.T_BOOK_ISSUE_TABLE.

    Error says as 'Object Query<T_BOOK_ISSUE_TABLE>' does not contain a definition for 'remove' and no extension method 'remove' accepting a first argument of type'Object Query<T_BOOK_ISSUE_TABLE>'could be found(are you missing a directive or an assembly reference?)
    How to get rid of this error?

    Wednesday, October 21, 2015 7:49 AM

All replies

  • User753101303 posted

    Hi,

    And 'ise" is your own data layer? It seems you are trying to call Remove against a *query*. It should be called against a *DbSet* (and then call DbContext.SaveChanges). Does your ise variable expose a DbSet?

    My understanding is that you are trying to delete a row from your db.

    Wednesday, October 21, 2015 8:22 AM
  • User-256597427 posted

    Let me Send you full CODE then. Please Let me know where I am going Wrong. Hope you help me to get rid of this problem. Code as follows

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;

    namespace Iselibrary
    {
    public partial class Delete : Form
    {
    SqlConnection vid = new SqlConnection("Data Source=.;Initial Catalog=iselibrary;Integrated Security=True");
    //private object item;

    public Delete()
    {
    InitializeComponent();
    }
    private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
    {

    }

    private void button1_Click_1(object sender, EventArgs e)
    {
    this.Close();
    Home home = new Home();
    home.Show();
    }

    private void Update_Load(object sender, EventArgs e)
    {
    // TODO: This line of code loads data into the 'iselibraryDataSet1.T_BOOK_ISSUE_TABLE' table. You can move, or remove it, as needed.
    this.t_BOOK_ISSUE_TABLETableAdapter.Fill(this.iselibraryDataSet1.T_BOOK_ISSUE_TABLE);

    }

    private void button2_Click(object sender, EventArgs e)
    {
    String str = "Select * from T_BOOK_ISSUE_TABLE where (USN like '%' + @search + '%')";
    SqlCommand xp = new SqlCommand(str, vid);
    xp.Parameters.Add("@search", SqlDbType.NVarChar).Value = textBox1.Text;


    vid.Open();
    xp.ExecuteNonQuery();
    SqlDataAdapter da = new SqlDataAdapter();
    da.SelectCommand = xp;
    DataSet dat = new DataSet();
    da.Fill(dat, "USN");
    dataGridView1.DataSource = dat;
    dataGridView1.DataSource = dat.Tables[0];
    vid.Close();
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {

    }
    // Delete Button Details//
    private void button3_Click(object sender, EventArgs e)
    {
    iselibraryEntities ise = new iselibraryEntities();
    foreach (var item in dataGridView1.Rows)
    {
    DataGridViewRow row = item as DataGridViewRow;
    if (row.Selected)
    {
    string usn = row.Cells["USN"].Value.ToString();
    var issu = ise.T_BOOK_ISSUE_TABLE.FirstOrDefault(a => a.USN.Equals(usn));
    if (issu != null)
    {
    ise.T_BOOK_ISSUE_TABLE.remove
    }
    }
    }
    }

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {

    }
    }
    }

    THANK YOU

    Wednesday, October 21, 2015 9:20 AM