日期:2014-05-19  浏览次数:20475 次

关于将物品放入购物车的问题!!!
我做了个网上书店系统,现在正在做购物车!!
    我想把想购买的书籍点击购买后放入数据库中...数据库名: "gouwuche "~~~...
下面代码有点错误...但是我不知道错在那里!!!提示错误是:不允许从数据类型   varchar   到数据类型   money   的隐性转换(表   'NetBook.dbo.gouwuche ',列   'bookprice ')。请使用   CONVERT   函数来运行此查询。

SqlCommand   mycmd=new   SqlCommand( "insert   into   gouwuche(username,bookname,bookctg,bookhouse,bookprice)   values( ' "+Session[ "user "]+ " ', ' "+this.lblname.Text+ " ', ' "+this.lblctg.Text+ " ', ' "+this.lblhouse.Text+ " ', ' "+this.lblprice.Text+ " ') ",mycon);

  ~~~~~样怎样转换才可以把书籍填加到数据库呢?
      还有个简单点的问题,就是我登陆成功后,我想退出...是用什么代码?请高手指教~~~谢谢`````


页面详细代码如下:

private   void   Page_Load(object   sender,   System.EventArgs   e)
{
string   bookID=Request.QueryString[ "bookID "].ToString();
if(!this.IsPostBack)
{
SqlConnection   con=DB.DBCon();
con.Open();
SqlCommand   cmd=new   SqlCommand( "select   *   from   book   where   bookID= ' "+bookID+ " ' ",con);
SqlDataReader   sdr=cmd.ExecuteReader();
sdr.Read();
this.lblname.Text=sdr.GetString(1);
this.lblctg.Text=sdr.GetString(2);
this.lblhouse.Text=sdr.GetString(3);
this.lblprice.Text=sdr.GetSqlMoney(4).ToString();
this.lbltime.Text=sdr.GetSqlDateTime(6).ToString();
this.lblidt.Text=sdr.GetString(7);
this.imgphoto.ImageUrl= "/网上书店/bookphoto/ "+sdr.GetString(5);
con.Close();
}

//   在此处放置用户代码以初始化页面
}

#region   Web   窗体设计器生成的代码
override   protected   void   OnInit(EventArgs   e)
{
//
//   CODEGEN:   该调用是   ASP.NET   Web   窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///   <summary>
///   设计器支持所需的方法   -   不要使用代码编辑器修改
///   此方法的内容。
///   </summary>
private   void   InitializeComponent()
{        
this.ImageButton1.Click   +=   new   System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.Load   +=   new   System.EventHandler(this.Page_Load);

}
#endregion

private   void   ImageButton1_Click(object   sender,   System.Web.UI.ImageClickEventArgs   e)
{
if(Session[ "user "]==null)
{
Response.Write( " <script> alert( '你还没登陆,请先登陆! '); </script> ");
}
else
{
SqlConnection   mycon=DB.DBCon();
mycon.Open();
SqlCommand   mycmd=new   SqlCommand( "insert   into   gouwuche(username,bookname,bookctg,bookhouse,bookprice)   values( ' "+Session[ "user "]+ " ', ' "+this.lblname.Text+ " ', ' "+this.lblctg.Text+ " ', ' "+this.lblhouse.Text+ " ', ' "+this.lblprice.Text+ " ') ",mycon);
                                mycmd.ExecuteNonQuery();
mycon.Close();
}
}
}
}

------解决方案--------------------
退出啊.这个我知道;
Session