虽然没改写SqlDbHelper.cs类的能力,但好不容易想出来的,放着留个纪念~~~~~

        /// <summary>
        
/// 执行SQL语句,返回第一行,第一列(sea)
        
/// </summary>
        
/// <param name="SQLString">sql语句</param>
        
/// <param name="cmdParms">参数数组</param>
        
/// <returns>int</returns>

        public int ExecuteSql4Value(string SQLString, params SqlParameter[] cmdParms)
        
{
            
using (SqlConnection connection = new SqlConnection(strConn))
            
{
                
using (SqlCommand cmd = new SqlCommand())
                
{
                    
try
                    
{
                        PrepareCommand(cmd, connection, 
null, SQLString, cmdParms);
                        
object r = cmd.ExecuteScalar();
                        
if (Object.Equals(r, null))
                        
{
                            
throw new Exception("value unavailable!");
                        }

                        
else
                        
{
                            
try int a = (int)r; }
                            
catch return 0; }
                            
return (int)r;
                        }

                        
                    }

                    
catch (System.Data.SqlClient.SqlException E)
                    
{
                        
throw new Exception(E.Message);
                    }

                    
finally
                    
{
                        cmd.Parameters.Clear();
                    }

                }

            }

        }
posted on 2008-03-14 20:56  超少  阅读(285)  评论(0编辑  收藏  举报