By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

Delete button code using checkbox

P: 1
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10.  
  11. namespace Iselibrary
  12. {
  13. public partial class Delete : Form
  14. {
  15. SqlConnection vid = new SqlConnection("Data Source=.;Initial Catalog=iselibrary;Integrated Security=True");
  16. //private object item;
  17.  
  18. public Delete()
  19. {
  20. InitializeComponent();
  21. }
  22. private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
  23. {
  24.  
  25. }
  26.  
  27. private void button1_Click_1(object sender, EventArgs e)
  28. {
  29. this.Close();
  30. Home home = new Home();
  31. home.Show();
  32. }
  33.  
  34. private void Update_Load(object sender, EventArgs e)
  35. {
  36. // TODO: This line of code loads data into the 'iselibraryDataSet1.T_BOOK_ISSUE_TABLE' table. You can move, or remove it, as needed.
  37. this.t_BOOK_ISSUE_TABLETableAdapter.Fill(this.iselibraryDataSet1.T_BOOK_ISSUE_TABLE);
  38.  
  39. }
  40.  
  41. private void button2_Click(object sender, EventArgs e)
  42. {
  43. String str = "Select * from T_BOOK_ISSUE_TABLE where (USN like '%' + @search + '%')";
  44. SqlCommand xp = new SqlCommand(str, vid);
  45. xp.Parameters.Add("@search", SqlDbType.NVarChar).Value = textBox1.Text;
  46.  
  47.  
  48. vid.Open();
  49. xp.ExecuteNonQuery();
  50. SqlDataAdapter da = new SqlDataAdapter();
  51. da.SelectCommand = xp;
  52. DataSet dat = new DataSet();
  53. da.Fill(dat, "USN");
  54. dataGridView1.DataSource = dat;
  55. dataGridView1.DataSource = dat.Tables[0];
  56. vid.Close();
  57. }
  58.  
  59. private void textBox1_TextChanged(object sender, EventArgs e)
  60. {
  61.  
  62. }
  63. // Delete Button Details//
  64. private void button3_Click(object sender, EventArgs e)
  65. {
  66. iselibraryEntities ise = new iselibraryEntities();
  67. foreach (var item in dataGridView1.Rows)
  68. {
  69. DataGridViewRow row = item as DataGridViewRow;
  70. if (row.Selected)
  71. {
  72. string usn = row.Cells["USN"].Value.ToString();
  73. var issu = ise.T_BOOK_ISSUE_TABLE.FirstOrDefault(a => a.USN.Equals(usn));
  74. if (issu != null)
  75. {
  76. ise.T_BOOK_ISSUE_TABLE.Remove  /* as error occurs here I have not completed the code*/
  77. }
  78. }
  79. }
  80. }
  81.  
  82. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  83. {
  84.  
  85. }
  86. }
  87. }
  88.  
As soon as i complete ise.T_BOOK_ISSUE_TABLE. in If loop, I dont get a dropdown for Remove. Why so? and 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?)
Please let me know where im going wrong or anyone out there please help me to write delete button code using checkbox checked. Hope anyone in forum helps....
Thank you
Oct 22 '15 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.