473,385 Members | 1,622 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,385 software developers and data experts.

Help on deleting a single row from a datagrid & DB (VB.net&sql server 2000)

navanova
hi guys, I'm developing an application using vb.net and sql server 2000. the data in the database are shown on the form using datagrid. I want to delete a single row from the datagrid as well as from the database by just pressing a delete button on the form. How do I do that.

Thank you
Jun 21 '07 #1
3 3000
dip_developer
648 Expert 512MB
hi guys, I'm developing an application using vb.net and sql server 2000. the data in the database are shown on the form using datagrid. I want to delete a single row from the datagrid as well as from the database by just pressing a delete button on the form. How do I do that.

Thank you
set the DataKey of the Datagrid to the Primary key of your table. Now for selection of records from the datagrid you may put a checkbox to every row of the grid.
while deleting (in DELETE button's Click event handler) check which checkbox is checked ......retreive the datakey and execute a simple sql query like
DELETE FROM myTable WHERE primary_key_value=datakeyvalue

after that Bind the datagrid again.
Jun 21 '07 #2
berry
46
set the DataKey of the Datagrid to the Primary key of your table. Now for selection of records from the datagrid you may put a checkbox to every row of the grid.
while deleting (in DELETE button's Click event handler) check which checkbox is checked ......retreive the datakey and execute a simple sql query like
DELETE FROM myTable WHERE primary_key_value=datakeyvalue

after that Bind the datagrid again.
Hi dip_developer,
Do you have any example? Because i facing the same problem and i don't know how to set the datakey to primary key.
Thank you very much..
Jun 28 '07 #3
sindhu
54
incude primary key column in the grid bound column. set DataKetield of the datagrid to the name of the Primarykey
suppose ur Primary key is Product_ID

set
DataKeyField="Product_ID"

if u don wanna show the primary key column to the user u can set it as invisible
Datagrid1.Columns[0].visible=false;

to get the primary key value
DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e)
{
int ro = e.Item.ItemIndex;
string strID= datagrid1.Datakeys[ro].tostring();//now u have the primary key of the row
string strQuery= "delete from products where Product_ID='+strID+"'";
deleting procedure....




}
Jun 28 '07 #4

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

Similar topics

1
by: Shock | last post by:
Hi everybody, I just wrote my first two triggers and from the minimal amount of testing I have done, they work! However, I was hoping I could get some feedback from those of you more...
1
by: aperez | last post by:
I have an Access 97 database that I connect to a SQL Server 2000 through ODBC. I have to manually set up the ODBC connection on each user's machine if I want them to be able to use the application...
1
by: MrNobody | last post by:
What I was hoping to do was have a universal Windows Form which features a DataGrid. This Formcould be accessed from several different points of entry, each one may require a different style...
2
by: Manish Naik | last post by:
Hi, Using ASP.Net, I want to store and retrive documents (Word, excel, etc) from SQL Server 2000 database. I have tried image type data field, but could not succed. Can any one help me please. ...
1
by: joshsackett | last post by:
Here is an obscure question that I am sure can be dealt with from a 10,000 ft view: I have installed Fuego (an enterprise level BPM). Another application was built in-house to connect to Fuego...
0
by: bid006 | last post by:
I have a CSV file.User selects the location of this CSV file. I need to send this CSV file to SQL Server which is on a different machine and insert it into a table. I know there is something called...
3
by: narasimha26 | last post by:
How to do online chatting in asp.net1.1 and sqlserver2000
3
by: donafran | last post by:
Hi. newbie here. Also new to coding in SQL. Struggling with how to implement the following psuedo-code in SQL server 2000. Sample data is at the bottom. Thanks for ANY suggestions !! **...
0
by: Sreenath Rao Nellutla | last post by:
Hai All, 1. I need help regarding displaying Date in to DataGrid from SQL Server 2000 database in the required format. Sql Server data : smalldatetime DataGrid : Date (Only I want. But...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.