textID.Text=Session["ID"].ToString();
textName.Text=Session["Name"].ToString();
if(Session["admin"].ToString()==""&&Session["lingdao"].ToString()==""&&Session["chengyuan"].ToString()=="")
{
Response.Redirect("login.aspx");
}
else
{

}
textID.Text=Session["ID"].ToString();
textName.Text=Session["Name"].ToString();
string sql="select JiHuaMuBiao from jihuamubiao where ID='"+Session["ID"].ToString()+"'";
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connection"]);
SqlCommand comm=new SqlCommand(sql,conn);
try
{
conn.Open();
SqlDataReader reader=comm.ExecuteReader();
if(reader.Read())
textContent.Text=reader.GetValue(1).ToString();
}
catch(Exception ee)
{
Response.Write("<script languge=javascript> alert('"+ee.Message+"');</script>;");
}
finally
{
conn.Close();
}为什么在我的textContent上面不能显示数据库里面相应列的值呢?我调试的时候都没有到reader.read那句话,是不是我的sql语句错误了

解决方案 »

  1.   

    select JiHuaMuBiao from jihuamubiao where ?
    textContent.Text=reader.GetValue(1).ToString();
    ==》textContent.Text=reader.GetValue(0).ToString();
      

  2.   

    不是啊,我现在就是想根据session传过来的值来查询数据库中第二列的值并把它取出来的,所以应该还是GetValue(1)的吧
      

  3.   

    asp.net(c#)技术交流  18590648
      

  4.   

    我用断点看过,if(reader.Read())这句根本执行不到,到底哪里出错呢?高手帮忙看看好吗?
      

  5.   

    LZ,如何执行了read(),也会报错,因为你查出来只有一列,而LZ取值,却第二列
    还有,如是SQL语句错误,自己可以到SQL查询分析器上面执行一下,看看有没有错或有没有记录?
      

  6.   

    textContent.Text=reader[第二列字段].tostring();
      

  7.   

    谢谢以上各位,问题我解决了,原来我的数据库设计有问题,不是语句的问题,谢谢。
    在这里我还想请教一个问题,就是在datagrid里面的一列模板里我放进了一个超链接,请问怎么实现点击一行里面的超链接就在另外一个页面显示对应行的数据呢?主要的问题是怎么实现点击当前行啊?不知道在哪里写代码