question

Dikshadudi-8186 avatar image
0 Votes"
Dikshadudi-8186 asked Dikshadudi-8186 commented

How to can we get the row details of the row getting detete in vb. Net

I want to get the row details of this query

194945-screenshot-2022-04-21-09-44-21-04-99c04817c0de5652.jpg


dotnet-aspnet-generaldotnet-aspnet-webformsdotnet-aspnet-webpages
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Dikshadudi-8186 ,
What's your meanings? You want to get details of the deleting row? When? Before deleting?

Best regards,
Yijing Sun

0 Votes 0 ·

Actually i want the detail of column of the row which is going to deleted.

I am here deleting from one table.
195074-screenshot-73.png


Now i want the detail of the column datetime of the row which is going to be deleted. So that i can delete from another table which has the same column

195045-screenshot-74.png


0 Votes 0 ·
screenshot-73.png (307.1 KiB)
screenshot-74.png (301.3 KiB)
Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered Dikshadudi-8186 commented

first you should fix the sql injection Security flaw in your code.

you should really use triggers rather than code to handle cascading deletes. but you can use the output clause to get the key fields

     var query = @" 
         delete orders 
         where prod_id =@pid and user_id=@uid 
         output deleted.Id 
     "; 
     
     using (var conn = new SqlConnection(strcon)) 
     { 
         conn.Open(); 
         var cmd = new SqlCommand(query, conn); 
         cmd.Parameters.AddWithValue("@pid", prodid); 
         cmd.Parameters.AddWithValue("@uid", user_id); 
         using (var reader = cmd.ExecuteReader()) 
         { 
             while(reader.HasRows) 
             { 
                 Console.WriteLine(reader.GetSqlInt32(0)); 
             } 
         } 
     } 
 } 
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ok thank you so much for your reply.

0 Votes 0 ·
AgaveJoe avatar image
0 Votes"
AgaveJoe answered Dikshadudi-8186 commented

Now i want the detail of the column datetime of the row which is going to be deleted. So that i can delete from another table which has the same column

Seems like a very simply solution. Execute a "SELECT" query to get the record then do the "DELETE". However, needing a DateTime value to delete another records sounds like a design bug.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ok thanks, but i already figured it out.

0 Votes 0 ·