日期:2014-05-17  浏览次数:20340 次

自学.net求解:InvalidCastException: 指定的转换无效。
本帖最后由 qq13589324 于 2013-03-06 18:28:10 编辑
小弟新手自学。net 现在遇到问题,不知道改如何改代码。
主要是在前台用  <%=usermail%>  这种代码调用后台参数的   其中 数据库中”c_etprs_name“ 这个字段的数据为中文  前台用<%=names%> 调用的    但是不知道 获取数据库 的这些值 , 弄了 一天也没结果
还请各位大仙指教!1


错误信息:
指定的转换无效。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.InvalidCastException: 指定的转换无效。

源错误: 


行 63:                     {
行 64:                         userid = s_lg_id;
行 65:                         usermail = Convert.ToString(sdr.GetDecimal(1));
行 66:                         names = Convert.ToString(sdr.GetDecimal(2));
行 67:                         usermny = Convert.ToString(sdr.GetDecimal(3));
 
以下后台代码
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Runtime.CompilerServices;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class UserTop : System.Web.UI.UserControl
{
    clsPub pubfun = new clsPub();
    protected string nametm = "";
    protected string username = "";
    protected string usermail = "";
  
    protected string namemny = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GetUserAcntInfo();
            // lbl_lg_count.Text = "0 次";
        }

    }

    protected void GetUserAcntInfo()
    {
        string s_lg_id = pubfun.GetRolesIDAsNameEx(Context);
        SqlConnection sc = pubfun.GetConnEx();

        try