944,155 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 9300
  • ASP.NET RSS
Jun 5th, 2007
0

delete a row in a sql databse

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sajithkahawatta is offline Offline
5 posts
since Apr 2007
Jun 6th, 2007
0

Re: delete a row in a sql databse

What you could do is add DataKeyNames to the GridView and set your table column names in there i.e.

ASP.NET Syntax (Toggle Plain Text)
  1. <asp:GridView ID="GridView1" runat="server"
  2. DataKeyNames="PNR,Credit Card Number,Email Address,Passenger Name,Passport Number,IP Number">
And in your GridView1_RowDeleting you'll be able to build a query like this...

vb Syntax (Toggle Plain Text)
  1. 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"))
Reputation Points: 10
Solved Threads: 2
Newbie Poster
Blackred is offline Offline
10 posts
since Apr 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: XML Namespace prefix problem
Next Thread in ASP.NET Forum Timeline: DropDownList....Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC