代码如下
protected void Button2_Click(object sender, EventArgs e)
{
string connstring = "Data Source=.\\sqlexpress;Initial Catalog=library;Integrated Security=True"; SqlConnection conn = new SqlConnection(connstring);
conn.Open();
string sel1, sel2;
sel1 = "select bookname from books where bookid = '" + TextBox3.Text + "'";
sel2 = "select quantity from books where bookid = '" + TextBox3.Text + "'";
SqlCommand cmd1 = new SqlCommand(sel1, conn);
SqlDataReader libDa1 = cmd1.ExecuteReader();
if (libDa1.Read())
{
Response.Write("成功!"); } else
{
Response.Write("<script language=javascript>alert (不存在此书目,返回!');</script>");
} conn.Close(); }
****************************************************************************************************
if语句还嵌套别的语句,为了调试,我把它改成 Response.Write("成功!");可是每次都都不执行else
protected void Button2_Click(object sender, EventArgs e)
{
string connstring = "Data Source=.\\sqlexpress;Initial Catalog=library;Integrated Security=True"; SqlConnection conn = new SqlConnection(connstring);
conn.Open();
string sel1, sel2;
sel1 = "select bookname from books where bookid = '" + TextBox3.Text + "'";
sel2 = "select quantity from books where bookid = '" + TextBox3.Text + "'";
SqlCommand cmd1 = new SqlCommand(sel1, conn);
SqlDataReader libDa1 = cmd1.ExecuteReader();
if (libDa1.Read())
{
Response.Write("成功!"); } else
{
Response.Write("<script language=javascript>alert (不存在此书目,返回!');</script>");
} conn.Close(); }
****************************************************************************************************
if语句还嵌套别的语句,为了调试,我把它改成 Response.Write("成功!");可是每次都都不执行else
能查出数据来。。它就不会进else
用值带进去看看在SQL数据库里能不能查出数据就知道了
试试,看执行else不!!if (false)
{
Response.Write("成功!"); } else
{
Response.Write("<script language=javascript>alert (不存在此书目,返回!');</script>");
}
偏偏button2不行,怎么回事啊 ——!
************************************************************
TextBox2代码
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
SqlConnection libCon = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=library;Integrated Security=True");
libCon.Open();
string BorSQL;
BorSQL = "select rName from Reader where readerid = '" + TextBox2.Text + "';";
SqlCommand StuIns = new SqlCommand(BorSQL, libCon);
SqlDataReader libDa = StuIns.ExecuteReader();
//libDa.Read();
if (libDa.Read())
{
Label3.Text = "读者姓名:" + libDa.GetString(0);
Label5.Text = "读者借图情况";
} else
{
Label3.Text = "不存在该读者";
Label5.Text = "";
}
libDa.Close();
libCon.Close();
}
messagebox.show(libDa1.Read().toString())
少个',调试下看看,我觉得应该是执行了,但是页面你没看到执行结果,因为js错误
呵呵,没仔细看。
不过LZ一直说的是Else没被执行,因此也就没去看else中的内容。
但很显然,else是被执行了的。