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型的,在这里显示不出来价格调试界面
catch {
TBbookname.Text = "没有此书";
为什么这里就是认定没有"此书"?
我已经改过来了,谢谢关心,ExecuteScalary只能返回一个值
有没有错误信息呢?
你看看catch吃掉了什么错误