Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
plz help me....,
i want to delete first row record from table on click of link button delete.
Table row record likes as follow:
UID Name MobileNo FID Action
15 Ram 8057965420 NULL Delete
10 shyam 12 Delete

for this i use stored procedure by passing to int datatype values UID and FID.
problem is here UID=15 is ok, but FID=NULL
how to pass int FID as null in stored procedure.



Thanks in advance........
Posted
Comments
Mohamed Mitwalli 14-May-12 1:20am    
Hi , You want to delete first Record by passing FID=NULL isn't
dA.d 14-May-12 1:41am    
Thanks for reply..
in my table have some records only few records have FID=null and other records have unique value, so when i want to delete FID=null record then it will delete when i want to delete some other record which FID=12 so it will delete and then i pass Fid=12 in stored procedure.
Mohamed Mitwalli 14-May-12 2:43am    
Check my solution Let me know if there is problem

Hi ,
Check this
SQL
CREATE PROCEDURE usp_Delete
(
@UID int ,@FID  int =NULL
)
AS
BEGIN
SET NOCOUNT ON;

DELETE FROM TableName WHERE UID=@UID and  FID = @FID

END


C#
void Delete(int uid, int? fid)
 {
     using (
       SqlConnection con =
           new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
     {
         con.Open();
         using (SqlCommand cmd = new SqlCommand("usp_Delete", con))
         {
             cmd.Parameters.AddWithValue("@UID", uid);
             cmd.Parameters.AddWithValue("@FID", fid);
             cmd.ExecuteNonQuery();
         }

     }

 }


Best Regards
M.Mitwalli
 
Share this answer
 
I am not able to understand why you might want to do this way nevertheless to answer your question, If you need to pass the null value for any parameter of stored procedure then you can use DBNull.Value
 
Share this answer
 
v2
Comments
dA.d 14-May-12 2:14am    
Thanks for replay...
i want to delete record from table on specific row id for than i pass two parameters in stored procedure. passing that parameter we delete the specific row from table. and i used dbnull.value but it not accepted.
Hi,


You can write in ur stored procedure


SQL
delete from xys where UID=15 and (FID=28 or FID is NULL)
 
Share this answer
 
SQL
DELETE FROM TableName WHERE UID='15'and  FID  is null
it will work in Stored procedure . try it


All the best
 
Share this answer
 
v2

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