473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How to give code in C#.NET for deleting a row from a datagridview?

How to give code in C#.NET for deleting a row from a Datagridview tool by simply selecting it or else in the click event of a button? what is the error in this code?
Expand|Select|Wrap|Line Numbers
  1. SqlConnection con = new SqlConnection("server=INTEL-C222E9040\\SQLEXPRESS;Database=internetspammonitor;uid=sa;pwd=123;");
  2.             con.Open();
  3.             string loc =(dataGridView1.SelectedRows[0].Cells[1].Value).ToString();
  4.             int locc = Convert.ToInt32(loc);
  5.             SqlCommand cmd = new SqlCommand("Delete from downloadscheduler where URL-location='"+locc.ToString()+"';");
  6.             //cmd.Parameters.AddWithValue("@username", textBox1.Text);
  7.             dbclass.Execute(cmd);
  8.             Fillgrid();
  9.             MessageBox.Show("Deleted Successfully");
  10.  
Feb 13 '11 #1
1 2142
Hey manju,
1) First of all, never write DELETE Statement in Code. always do this stuff in Stored Procedure.This is Best practise to avoid SQL Injection
2) Second thing, if are going to delete some rows then instead of WHERE, u can use IN statement that will allow u to do bulk Deletion...
3) So Fill datagrid...then store downloadscheduler table's unique ID(Primary key Column)value in array or List..Then Pass it Stored Procedure...return 0 on success else return something like -999(depends on u)
4) If u got 0 Deletion successfull, else POP up some Message to user

Follow this...might ur Problem solved...
Feb 13 '11 #2

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

Similar topics

0
by: shashi | last post by:
i want to learn more about data grid viewer in vb 2005 and more about Sql server 2005 sent links , doc files etc to me regarding my problem thanks in advance hoping for reply
3
by: Art | last post by:
Hi, Forgive me for posting this message in 2 groups -- it appears that the Data Access group isn't very active, so I'm posting again here: I have a DataTable that I want to fill using a...
1
by: vikas2923 | last post by:
Thanx for ur reply but could you please tell me the code for uploading one image through FSO because i am new to this filed Thanx
7
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so...
0
by: Scotty | last post by:
Hi, Hope someone can help me I have a datagridview sith data Code below works fine if I print the data if there is only 1 page (without using '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! If...
3
by: =?Utf-8?B?THVib21pcg==?= | last post by:
Hi, I have a DataGridView that displays data from one table from database. I didn’t implement any my code, I just used wizard to do all the work with DatagridView populating. Visual Studio...
3
by: Bhagya | last post by:
DataSet ds = new DataSet(); DataTable dtAddUsers = new DataTable("Names"); public void CreateDataset() { dtAddUsers.Columns.Add("Name", typeof(String)); dtAddUsers.Columns.Add("Place",...
1
nev
by: nev | last post by:
Happy Easter to all! I have a problem with a datagridview. I placed code in a button click event as follows: dim dtt as datatable = dataset.employees.copy dtt.DefaultView.RowFilter = "='" &...
18
by: Andrus | last post by:
Marc, Thank you very much. I have issue on implementing add row properly using this. User presses down arrow in last row in grid starting adding new row. Then user changes its mind desiding...
0
by: kumardharanik | last post by:
Hi Friends, The below code is a sample code for insert, update and delete using datagrid but i need to convert the entire code for datagridview.. Plsss help me.. using System; using...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.