fhauin 2016-05-19 08:42 采纳率: 100%
浏览 4374
已采纳

在将 varchar 值 'JAZZ' 转换成数据类型 int 时失败。

图片说明

代码如下:
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 Describe : System.Web.UI.Page
{
SqlHelper sqloperate = new SqlHelper();
SqlConnection sqlconn = new SqlConnection(ConfigurationManager.ConnectionStrings["connStr"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
if (Session["users"] != null)
{
sqlconn.Open();
string sqlstr = "Select * from tb_GoodsInfo where GoodsID='" + Session["users"].ToString() + "'";
SqlDataAdapter myApter = new SqlDataAdapter(sqlstr, sqlconn);
DataSet myDS = new DataSet();
myApter.Fill(myDS, "tb_GoodsInfo");
if (myDS.Tables["tb_GoodsInfo"].Rows.Count > 0)
{

                DataRowView rowView = myDS.Tables["tb_GoodsInfo"].DefaultView[0];
                txtGoodsName.Text = Convert.ToString(rowView["GoodsName"]);
                txtKind.Text = Convert.ToString(rowView["GoodsKind"]);
                imgGoodsPhoto.ImageUrl = Convert.ToString(rowView["GoodsPhoto"]);
                txtGoodsDesc.Text = Convert.ToString(rowView["GoodsIntroduce"]);
            }


        }
        else
            Response.Write("<script>alert('您还没有登录,请登录后再使用,谢谢!');</script>");
    }
}



//关闭窗口
protected void btnClose_Click(object sender, EventArgs e)
{
    Response.Write("<script>window.close();</script>");
}

}

  • 写回答

4条回答 默认 最新

  • 胖子程序员 2016-05-20 16:09
    关注

    varchar对应取出来是string,如果你硬要转成int 也该是integer.parse

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd
  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 麒麟V10 arm安装gdal
  • ¥20 OPENVPN连接问题