Click here to Skip to main content
15,906,306 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I want to delete multiple rows from sql.

My code:

 USE [MyWebsite]
GO
/****** Object:  StoredProcedure [dbo].[DeletUserFromAdmin]    Script Date: 3/21/2013 7:54:08 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[DeletUserFromAdmin]

@userid int

as

DELETE FROM [dbo].[Users]
      WHERE usr_Id in (@userid) 


C#
 protected void Button1_Click(object sender, EventArgs e)
    {

        string id = "0";
        foreach (GridDataItem mm in grdAllUsers.Items)
        {

            if (mm.Selected)
            {
                id +="," + mm.GetDataKeyValue("usr_Id");
                Literal1.Text = id;
            }
            

        }

        Admin delet = new Admin();
        string req = delet.DeleteUserFromAdmin(id);
        id = string.Empty;
        LoadGridAllUsers();
        Literal1.Text += "REquest:" + req;

    }

SqlCommand cmd = new SqlCommand("DeletUserFromAdmin", con);
        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.Add("@userid", SqlDbType.Int).Value = id;

        try
        {
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }

            if (cmd.ExecuteNonQuery() > 0)
            {
                return "Succ";
            }
            else
            {
               return "UnSucc";
            }
        }

        catch(Exception ex)
        {

            return ex.Message;
        }
        finally
        {

            con.Close();
        }
    }
Posted
Updated 21-Mar-13 5:37am
v3
Comments
Richard C Bishop 21-Mar-13 11:30am    
Did you have a question?
vinodkumarnie 21-Mar-13 13:35pm    
Why you past this here...? Anything you want to ask..? Any problem you are facing...?

1 solution

string id = "0";

cmd.Parameters.Add("@userid", SqlDbType.Int).Value = id;


Why do you try to assign to an integer value a string one ?

But it's just a guess on what could be your problem, as you did not even describe it.
 
Share this answer
 
Comments
tree1371 21-Mar-13 14:21pm    
when i would saving my id of records for send to database (stored procedure) and delete i have problem because my string of my recorde 's id simple fllowing code:

Collapse | Copy Code

finall stirng id is:

0,1,2,3,4,5

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