注册 登录
编程论坛 ASP.NET技术论坛

未将对象引用设置到对象的实例

冷月烟云梦 发布于 2012-05-09 04:27, 806 次点击
public void GetGoodsInfo()
    {
        string strSql = "select * from Goodsinfo where Goodsid=" + Convert.ToInt32(Request["id"].Trim());
        SqlCommand myCmd = db0bj.GetCommandStr(strSql);
        DataTable dsTable = db0bj.GetDataSetStr(strSql, "Gdif");
        this.txtCategory.Text = gc0bj.GetClass(Convert.ToInt32(dsTable.Rows[0]["TypeID"].ToString()));
        this.txtName.Text = dsTable.Rows[0]["Goodsname"].ToString();
        this.txtAuthor.Text = dsTable.Rows[0]["Goodsauthor"].ToString();
        this.txtCompany.Text = dsTable.Rows[0]["Goodscompany"].ToString();
        this.txtMarketPrice.Text = dsTable.Rows[0]["Goodsmarketprice"].ToString();
        this.txtHotPrice.Text = dsTable.Rows[0]["GoodshotPrice"].ToString();
        this.ImageMapPhoto.ImageUrl = dsTable.Rows[0]["Goodsurl"].ToString();
        this.cbxCommend.Checked = dsTable.Rows[0]["Isrefinement"].ToString();


        this.isbool(cbxCommend, dsTable.Rows[0]["Isrefinement"].ToString());
        this.isbool(cbxDiscount, dsTable.Rows[0]["IsDiscount"].ToString());
        this.isbool(cbxHot, dsTable.Rows[0]["IsHot"].ToString());
        this.txtShortDesc.Text = dsTable.Rows[0]["GoodsIntroduce"].ToString();
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        string strUrl = Session["address"].ToString();
        Response.Redirect(strUrl);
    }
    public void isbool(CheckBox c, string s)
    {
        if (s=="1")
        {
            c.Checked = true;
            return;
        }
else
{
   c.Checked = false;
    return;


我是新手,实在不明白错在哪里了,很是郁闷……希望高手能给我一点儿指教!谢谢……
还有我在数据库中将Isrefinement,Isdiscount,Ishot的数据类型设置为char类型了,在这里无法将string转换为bool类型。但是在sql server 数据库中没有bool类型,只有bit类型,怎么办?在数据库中修改它的类型会提示丢失数据,最后还是没有修改成功,怎么办?
6 回复
#2
cnfarer2012-05-09 06:48
1.通常是null值作怪
2.bool型在SQL Server中就是用bit型(当然你也要可以用其它方式替代)
#3
刘杰明2012-05-11 22:05
string strSql = "select * from Goodsinfo where Goodsid=" + Convert.ToInt32(Request["id"].Trim());
未将对象引用到示例,大致是因为这句话出错了,其它的对DOM控件赋值没出错,我觉得应该先tostring 一下再去空格吧
#4
zwffff2012-05-11 23:27
回复 楼主 冷月烟云梦
调试一下,就知道了。。
#5
zwffff2012-05-11 23:28
欢迎加入.Net技术交流群:90925122
#6
bccnsir2012-05-14 11:52
数据库链接超时容易出现这样的问题
#7
lcawen2012-05-17 15:34
应该是连接数据库的配置文件出错了
1