You must Sign In to post a response.
  • Category: Visual Studio

    Delete button code using checkbox

    // 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?
  • #762925
    Hi bharthish,

    Could you please check whether "error" method is available in "iselibraryEntities".

    If it's available then I'm sure that is not latest dll your referring, I request you to please update the dll and add reference to that then rebuild the solution.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762930
    How to check whether "error" method is available in "iselibraryEntities".?

  • #762934
    GOT SOLUTION here it is....

    private void button3_Click(object sender, EventArgs e)
    {
    var selectedidlist = new List<string>();
    for (var rownum = 0; rownum < dataGridView1.Rows.Count; rownum++)
    {
    if (dataGridView1.Rows[rownum].Cells["Column1"].Value!=null && ((bool)(dataGridView1.Rows[rownum].Cells["Column1"]).Value))
    {
    selectedidlist.Add(dataGridView1.Rows[rownum].Cells["USN"].Value.ToString());

    }
    }

    if (selectedidlist.Count > 0)
    {

    var selectedListString = selectedidlist.Aggregate((current, next) => current + ", " + next);

    String str = "delete from T_BOOK_ISSUE_TABLE where USN in (@search)";
    SqlCommand xp = new SqlCommand(str, vid);
    xp.Parameters.Add("@search", SqlDbType.NVarChar).Value = selectedListString;

    vid.Open();
    xp.ExecuteNonQuery();
    vid.Close();
    Delete_Load(null, null);
    }

  • #762994
    Try this :-

    private void button3_Click(object sender, EventArgs e)

    {
    var selectedidlist = new List<string>();
    for (var rownum = 0; rownum < dataGridView1.Rows.Count; rownum++)
    {
    if (dataGridView1.Rows[rownum].Cells["Column1"].Value!=null && ((bool)(dataGridView1.Rows[rownum].Cells["Column1"]).Value))
    {
    selectedidlist.Add(dataGridView1.Rows[rownum].Cells["USN"].Value.ToString());

    }
    }

    if (selectedidlist.Count > 0)
    {

    var selectedListString = selectedidlist.Aggregate((current, next) => current + ", " + next);

    String str = "delete from T_BOOK_ISSUE_TABLE where USN in (@search)";
    SqlCommand xp = new SqlCommand(str, vid);
    xp.Parameters.Add("@search", SqlDbType.NVarChar).Value = selectedListString;

    vid.Open();
    xp.ExecuteNonQuery();
    vid.Close();
    Delete_Load(null, null);

    HOPE THIS HELPS.


  • Sign In to post your comments