当前位置: 代码迷 >> ASP.NET >> 错误详细信息: System.InvalidCastException: 指定的转换无效
  详细解决方案

错误详细信息: System.InvalidCastException: 指定的转换无效

热度:9259   发布时间:2013-02-25 00:00:00.0
异常详细信息: System.InvalidCastException: 指定的转换无效。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class QianFei_QianfeiXiangxi : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!this.IsPostBack)
        {
            string name = Request["name"];
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "select * from tb_qianfei where name='" + name + "'";
            cmd.ExecuteNonQuery();
            SqlDataReader sdr = cmd.ExecuteReader();
            sdr.Read(); 
            if (name!= "")
            {
                this.lblqfname.Text = sdr.GetString(0).ToString();
                this.lblzz.Text = sdr.GetString(1);
                this.lbllb.Text = sdr.GetString(2);
                this.lblrqzs.Text = sdr.GetDateTime(3).ToShortDateString();
                this.lblzzsj.Text = sdr.GetDateTime(4).ToShortDateString();
                this.lblje.Text = sdr.GetFloat(5).ToString();
                this.Lblzt.Text = sdr.GetString(6).ToString();
                this.lbljsr.Text = sdr.GetString(7).ToString();
            }
            else
            {
                Response.Write("暂无主题,不能显示");
                Response.Redirect("~/Default.aspx");//将该页跳转到指定的页面中
            }
  相关解决方案