本文介绍了C#类型转换错误从SqlDatatype.BIT到C#中的布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好 我得到< g class =" gr_ gr_87 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace"数据-GR-ID =" 87" id =" 87"> a a< / g>此行上的类型转换错误 SqlParameter参数= oCmd.SelectCommand.Parameters.Add(" @ blnSelectStatus",SqlDbType.Bit).Value = blnSelectByIDStatus .; 下面给出了代码片段。 请帮忙。 提前致谢。   public bool displayEventGalleryDetailsByGalleryByID(int ipknEventGalleryID)         { $             bool blnSelectByIDStatus = false;            串zpConnectionString = WebConfigurationManager.ConnectionStrings [" MSC-UFCFUD-60-M"] ConnectionString.ToString(); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; SqlConnection oCon = new SqlConnection(zpConnectionString);             SqlDataAdapter oCmd = new SqlDataAdapter(); $             oCmd.SelectCommand = new SqlCommand(" usp_EventGallery_Image_By_Image_Id_Select",oCon);             oCmd.SelectCommand.CommandType = CommandType.StoredProcedure;             oCmd.SelectCommand.Parameters.Add(QUOT; @ ipknImageID" ;, SqlDbType.Int)。价值= ipknEventGalleryID; &NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; //设置返回值的参数 SqlParameter参数= oCmd.SelectCommand.Parameters.Add(" @ blnSelectStatus",SqlDbType.Bit).Value = blnSelectByIDStatus .;             parameter.Direction = ParameterDirection.ReturnValue; $ $   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;试试            {                 DataSet oDs = new DataSet();                 oCmd.Fill(oDs); $                ;&NBSP; //检索ReturnValue。                 Int32 rowCount =(Int32)oCmd.SelectCommand.Parameters [" @ blnSelectStatus"]。Value; $      ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;如果((int)的oCmd.SelectCommand.Parameters [" @ blnSelectStatus"]。值及0) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; blnSelectByIDStatus = true;                 }             }             catch(例外情况)             {                抛出新的ApplicationException("数据错误。");             }            最后是            {                 oCmd.Dispose();&                oCon.Close();             }            返回blnSelectByIDStatus; $         }     }            &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;            &NBSP;&NBSP; 解决方案 Hi AllI am getting <g class="gr_ gr_87 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="87" id="87">an a</g> type conversion error on this lineSqlParameter parameter = oCmd.SelectCommand.Parameters.Add("@blnSelectStatus", SqlDbType.Bit).Value = blnSelectByIDStatus.;The code snippet is given below.Please help.Thanks in advance. public bool displayEventGalleryDetailsByGalleryByID(int ipknEventGalleryID)        {            bool blnSelectByIDStatus = false;            string zpConnectionString = WebConfigurationManager.ConnectionStrings["MSC-UFCFUD-60-M"].ConnectionString.ToString();            SqlConnection oCon = new SqlConnection(zpConnectionString);            SqlDataAdapter oCmd = new SqlDataAdapter();            oCmd.SelectCommand = new SqlCommand("usp_EventGallery_Image_By_Image_Id_Select", oCon);            oCmd.SelectCommand.CommandType = CommandType.StoredProcedure;            oCmd.SelectCommand.Parameters.Add("@ipknImageID", SqlDbType.Int).Value = ipknEventGalleryID;            //Set the parameter for the return valueSqlParameter parameter = oCmd.SelectCommand.Parameters.Add("@blnSelectStatus", SqlDbType.Bit).Value = blnSelectByIDStatus.;            parameter.Direction = ParameterDirection.ReturnValue;            try            {                DataSet oDs = new DataSet();                oCmd.Fill(oDs);                // Retrieve the ReturnValue.                Int32 rowCount = (Int32)oCmd.SelectCommand.Parameters["@blnSelectStatus"].Value;                if ((int)oCmd.SelectCommand.Parameters["@blnSelectStatus"].Value > 0)                {                    blnSelectByIDStatus = true;                }            }            catch (Exception ex)            {                throw new ApplicationException("Data error.");            }            finally            {                oCmd.Dispose();                oCon.Close();            }            return blnSelectByIDStatus;        }    }                                                              解决方案 这篇关于C#类型转换错误从SqlDatatype.BIT到C#中的布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 21:15