首页 新闻 会员 周边 捐助

价格显示不出来

0
[已解决问题] 解决于 2017-07-03 11:31

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
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;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void BTQuery_Click(object sender, EventArgs e)
    {
        string connString;
        string bookID;
        bookID = TBbookID.Text;
        connString = "Initial Catalog=onlineBookstore;Data Source=(local);Integrated Security=SSPI;";
        SqlConnection Conn = new SqlConnection(connString);
        SqlCommand QueryCommand = new SqlCommand("select bookname,sellprice from bookinfo where bookID=@bookID ", Conn);
        SqlCommand QueryCommand1 = new SqlCommand("select sellprice from bookinfo where bookID=@bookID ", Conn);
      
        QueryCommand.Parameters.Add("@bookID", SqlDbType.VarChar, 25);
        QueryCommand.Parameters["@bookID"].Value = bookID;
        Conn.Open();        try

        {         
                string booknameValue = (string)QueryCommand.ExecuteScalar();
                TBbookname.Text = Convert.ToString(booknameValue);           
        }
        catch {
            TBbookname.Text = "没有此书";
        }
        try
        {          
                string sellpriceValue = (string)QueryCommand.ExecuteScalar();
                TBsellprice.Text = Convert.ToString(sellpriceValue);    
        }
        catch
        {
            TBsellprice.Text = "没有价格";
        }
        finally
        {
            Conn.Close();
        }
    }
}

 

sellprice 在数据库中是money型的,在这里显示不出来价格调试界面

泽峰的主页 泽峰 | 初学一级 | 园豆:48
提问于:2017-07-02 16:20
< >
分享
最佳答案
0

      catch {
            TBbookname.Text = "没有此书";
      为什么这里就是认定没有"此书"?

奖励园豆:5
~扎克伯格 | 小虾三级 |园豆:1923 | 2017-07-03 09:15

我已经改过来了,谢谢关心,ExecuteScalary只能返回一个值

泽峰 | 园豆:48 (初学一级) | 2017-07-03 11:31
其他回答(1)
0

有没有错误信息呢?

你看看catch吃掉了什么错误

肖恩部落 | 园豆:585 (小虾三级) | 2017-07-03 11:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册