网格中显示异常消息

网格中显示异常消息

问题描述:



网格视图以显示记录usind id
如果id 25有3行...
我通过单击按钮删除了所有3行....
如果id 25中没有记录..
我输入ID 25表示它显示消息;没有可用的记录
我想要此消息异常的代码
数据库处于存储过程中...

表名称是:Exceptionlog
存储过程是:getexception_delete

编辑此代码,我希望它检查id25条目是否可用

Hi,

grid view to display the records usind id
if the id 25 have 3 rows ...
i deleted all 3 rows by using button click ....
if no records in id 25 ..
i enter the id 25 means it show the message ;there is no no record avail
i want the code for this message exception
database are in stored procedure...

table name is : Exceptionlog
stored procedure is: getexception_delete

edit this code i want it check it id25 entry is avail or not

 SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "getexception_delete";
        cmd.Connection = con;

        SqlParameter param = new SqlParameter();
        param.ParameterName = "@ExceptionLogID";
        param.SqlDbType = SqlDbType.Int;
        param.Direction = ParameterDirection.Input;
        LinkButton lnk = (LinkButton)sender;
        param.Value = lnk.CommandArgument; ;
        cmd.Parameters.Add(param);

SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
   {
       Response.Write("NO SESSION");
   }
   else
   {
       Response.Write("Invalid");
   }
   GridView1.DataSource = dr;

   GridView1.DataBind();
   con.Close();

}
}
}

我只是给你一个想法,
删除SP之前

您将必须执行以下操作

I am giving you just an idea,
Before delete SP

You''ll have to do something like this

SqlCommand cmd=new SqlCommand();
cmd.CommandText="Select * from table where id = 25"//instead of query you can use your own SP
SqlDataReader reader=cmd.ExecuteReader();
if(!reader.Read())
{
//print message
}
else

{
//delelte
}


如果在您的SP中已声明
if in your SP you have stated
SET NOCOUNT OFF

,并且您使用ExecuteNonReader,返回的int值将告诉您涉及的行数.如果涉及的行数为0,则可以引发异常或将某些文本放入文字或标签控件中.

and you use a ExecuteNonReader the int value returned tells you the number of rows involved. If the number of rows involved is 0, than you can throw an exception or put some text in a literal or label control.