Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL
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) 
 
 

 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 21-Mar-13 6:28am
Edited 21-Mar-13 6:37am
_duDE_8K
v3
Comments
richcb at 21-Mar-13 11:30am
   
Did you have a question?
vinodkumarnie at 21-Mar-13 13:35pm
   
Why you past this here...? Anything you want to ask..? Any problem you are facing...?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
tree1371 at 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)

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 519
2 Maciej Los 305
3 BillWoodruff 250
4 Mathew Soji 195
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 21 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100