Click here to Skip to main content
15,920,383 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi guys, ive got a problem. Currently im reading all the tutorials regarding on how to delete a record but still can't understand it. Plss help me find a site or examples on how to delete it using/without gridview... thanks and more power
Posted

variuos links are there on net

see this link

http://www.dotnetspark.com/kb/643-how-to-editupdatedelete-gridview.aspx[^]
 
Share this answer
 
Comments
Ankur\m/ 2-May-11 1:06am    
OP doesn't want to use a GridView.
Ankur\m/ 2-May-11 1:51am    
Apparently he does. He left me a comment saying that.
Create a command object, write a delete query and execute the query using command object. There are many other ways. But I don't think this is what you exactly want. You need to more specific and describe your scenario properly to get a better answer.
UPDATE:
OP wrote: Sir There is one button named DELETE and when i highlighted a record using a gridview and click the button, it will be automatically deleted. Is it possible? Now i can only view it via gridview
You could have easily found the examples using Google/Bing. Here are few:
MSDN - GridView Examples for ASP.NET 2.0: Deleting a GridView's Underlying Data[^]
CodeProject - GridView Delete, with Confirmation[^]
CodeProject - Insert, Update, Delete with Gridview....simple way[^]

I found all of them by doing this[^].
 
Share this answer
 
v2
Comments
janwel 2-May-11 1:22am    
Sir There is one button named DELETE and when i highlighted a record using a gridview and click the button, it will be automatically deleted. Is it possible? Now i can only view it via gridview
Ankur\m/ 2-May-11 1:25am    
Yes, it is possible. I am updating my answer with the link.
Without using gridview..



'Add following Namespace
using system.data;
using syste.data.sqlclient;

'Write on delete buttons click event

string query = "delete from tablename where primarykeycolumnname = value";
SQLConnection con = new sqlConnection('your connection string);
SQLCommand cmd = new SQLCommand(query, con);

try
{
    con.Open();
    cmd.ExecuteNonQuery();
}
catch
{
   'Handle Exception
}
finally
{
     con.Close();
}


and for gridview write the above code in the rowdeleting event

but the primarykeyvalue in the query will come from the follwing code

first of all set the datakeys properties of the gridview to primary key value

and now access the same for eg say ID is the primary key
so you can get its value in rowdeletingevent as

int value = gridview1.Items[gridview1.selectedIndex].value.tostring();

following the code above
 
Share this answer
 
Comments
janwel 2-May-11 1:22am    
Sir There is one button named DELETE and when i highlighted a record using a gridview and click the button, it will be automatically deleted. Is it possible? Now i can only view it via gridview
janwel 2-May-11 1:25am    
here is my code for viewing and sir my table doesnt have a primary key

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900