Click here to Skip to main content
15,916,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here i have stored procedure like this
SQL
create  PROCEDURE [dbo].[InsertDetails]
	
	@Cname varchar (50),
	@ImageName varchar (50),
	@imagepath varchar(50),
	@uploadedby varchar(50)
	
As
BEGIN
DECLARE @count INT
SET @count = (SELECT COUNT(*) FROM UUDetails)
IF @count >= 20

BEGIN
   PRINT 'You cannot insert more than 20 records'
   
END

ELSE
INSERT INTO UUDetails(UserName,ImageName,ImagePath,UploadedBy,UploadedDate)values(@Cname,@ImageName,@imagepath,@uploadedby,GETDATE() )

RETURN scope_Identity()
END


now i want to display this message in aspx page if total records are 20
C#
try
            {
              SqlConnection con;
              SqlCommand cmd;
              SqlParameter ret;
                        con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString);
              FileUpload1.SaveAs(Server.MapPath("Images/" + filename));
              cmd = new SqlCommand("dbo.InsertDetails", con);
              cmd.CommandType = CommandType.StoredProcedure;
              ret = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
              ret.Direction = ParameterDirection.ReturnValue;
              cmd.Parameters.Add(ret);
              cmd.Parameters.Add("@Cname", SqlDbType.VarChar, 50).Value = txtcustname.Text;
              cmd.Parameters.Add("@ImageName", SqlDbType.VarChar, 50).Value = filename;
              
                            cmd.Parameters.Add("@Uploadedby", SqlDbType.VarChar, 50).Value = txtuploadedBy.Text;
              con.Open();
              cmd.ExecuteNonQuery();
             
                int j = Convert.ToInt32(ret.Value);
                con.Close();

                if (j >= 0)
                {
                  Label1.Text = "<b1>Record sucessfully Inserted</b1>";
                 gvCustomer.DataBind();
                
                }
                          }
              
            catch (SqlException ex)
            {
              Label1.Text =ex.Message;
            }
            catch(Exception  ex)
            {
              throw ex;
            }

how to display an message if records are more than 20
please help me ..
Posted
Updated 4-Jul-12 0:37am
v2

See here: http://support.microsoft.com/kb/321903[^] - it has examples of raising exceptions in stored procedures.
 
Share this answer
 
Comments
shashavali 4-Jul-12 9:25am    
well thats helpfull.. but thing is that code is Vb.net
OriginalGriff 4-Jul-12 9:46am    
So rip out the DIM statements, and stuff a semicolon on the end... :laugh:
Or run it through an online translator: http://www.developerfusion.com/tools/convert/vb-to-csharp/

The bit you needed to read was immediately above the VB code anyway...
bbirajdar 21-Jul-12 0:57am    
@OP...Get the help from a software programmer. He will translate it for you
Hi,

use raiserror[^] method instead of
C#
PRINT 'You cannot insert more than 20 records'


Regards
Sebastian
 
Share this answer
 
v2
Comments
shashavali 4-Jul-12 9:24am    
thats helpfull ,well i want to this message in asp.net in try - catch block..
Any more...

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