| | |
delete a row in a sql databse
Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Apr 2007
Posts: 5
Reputation:
Solved Threads: 0
i want to delete a selected row from the database.the entries of
database is shown by a gridview and i do
<OnRowDeleting="GridView1_RowDeleting"> in source code.
i select and bind as follows.
[mycode]
string str = "select PNR,CreditCardNumber as 'Credit Card
Number',EmalAddress as 'Email Address',PassengerName as 'Passenger
Name',PassportNumber as 'Passport Number',IPNumber as 'IP Number' from
fraud_db order by PNR";
dbconn dc = new dbconn();
SqlConnection myConnection = new SqlConnection("Data
Source=IT0004493;Initial Catalog=IBE_fraud;User ID = sa ; password =
ecomtest ");//Trusted_Connection = yes;
myConnection.Open();
SqlCommand myCommand = new SqlCommand(str, myConnection);
SqlDataReader myReader = myCommand.ExecuteReader();
GridView1.DataSource = myReader;
GridView1.DataBind();
myReader.Close();
myConnection.Close();
[mycode]
now when i click on delete link it calls GridView1_RowDeleting(object
sender, GridViewDeleteEventArgs e) method
can i get the row entries of that row (i mean values of that row )
inside that method? i suppose to delete the row from db using that
entries of row using the query delete * from db where ....
(there is no primaty key in the table.)
is there any other easy way to delete a row from db selected in
gridview.
please help me.
database is shown by a gridview and i do
<OnRowDeleting="GridView1_RowDeleting"> in source code.
i select and bind as follows.
[mycode]
string str = "select PNR,CreditCardNumber as 'Credit Card
Number',EmalAddress as 'Email Address',PassengerName as 'Passenger
Name',PassportNumber as 'Passport Number',IPNumber as 'IP Number' from
fraud_db order by PNR";
dbconn dc = new dbconn();
SqlConnection myConnection = new SqlConnection("Data
Source=IT0004493;Initial Catalog=IBE_fraud;User ID = sa ; password =
ecomtest ");//Trusted_Connection = yes;
myConnection.Open();
SqlCommand myCommand = new SqlCommand(str, myConnection);
SqlDataReader myReader = myCommand.ExecuteReader();
GridView1.DataSource = myReader;
GridView1.DataBind();
myReader.Close();
myConnection.Close();
[mycode]
now when i click on delete link it calls GridView1_RowDeleting(object
sender, GridViewDeleteEventArgs e) method
can i get the row entries of that row (i mean values of that row )
inside that method? i suppose to delete the row from db using that
entries of row using the query delete * from db where ....
(there is no primaty key in the table.)
is there any other easy way to delete a row from db selected in
gridview.
please help me.
What you could do is add DataKeyNames to the GridView and set your table column names in there i.e.
And in your GridView1_RowDeleting you'll be able to build a query like this...
ASP.NET Syntax (Toggle Plain Text)
<asp:GridView ID="GridView1" runat="server" DataKeyNames="PNR,Credit Card Number,Email Address,Passenger Name,Passport Number,IP Number">
vb Syntax (Toggle Plain Text)
Dim strSql As String = String.Format("DELETE FROM myTable WHERE PNR = {0}, CreditCardNumber {1}, EmalAddress = {2}, PassengerName = {3}, PassportNumber = {4}, IPNumber = {5}", GridView1.DataKeys(e.RowIndex)("PNR"), GridView1.DataKeys(e.RowIndex)("Credit Card Number"), GridView1.DataKeys(e.RowIndex)("Email Address"), GridView1.DataKeys(e.RowIndex)("Passenger Name"), GridView1.DataKeys(e.RowIndex)("Passport Number"), GridView1.DataKeys(e.RowIndex)("IP Number"))
This station is non-operational.
![]() |
Similar Threads
- how to delete duplicate record in a table by using SQL query (MS SQL)
- How to delete using checkboxes (PHP)
- How to delete a row in text file? (Visual Basic 4 / 5 / 6)
- How to give 2 Conditions in an SQL Query (VB.NET)
- delete a record and update the dataset (VB.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: XML Namespace prefix problem
- Next Thread: DropDownList....Help
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 beginner bottomasp.net browser businesslogiclayer c# c#gridviewcolumn cac checkbox class compatible confirmationcodegeneration content contenttype countryselector courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv forms gridview gudi homeedition iframe iis javascript jquery listbox menu microsoft mouse mssql multistepregistration nameisnotdeclared news objects opera problem redirect registration relationaldatabases reportemail rotatepage schoolproject security serializesmo.table sessionvariables silverlight smartcard smoobjects software sql sql-server ssl textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webdevelopment webprogramming





