我通过GridView来读取出当前行的ID了,protected void LinkButton1_Click(object sender, EventArgs e)
{
string sid;
sid = ((LinkButton)sender).CommandArgument.ToString(); //这里获取到ID,已经测试输出sid的值为该行ID
string sql;
SqlConnection myconn;
SqlCommand mycommand;
myconn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbs"].ConnectionString);
sql = "select tname from users where id = '" + sid +"'" ;
mycommand = new SqlCommand(sql, myconn);
myconn.Open();
SqlDataReader aaa = mycommand.ExecuteReader();
Response.Write(aaa);
}
现在输出aaa的值无法输出,我很菜希望能帮忙。分数少见谅
{
string sid;
sid = ((LinkButton)sender).CommandArgument.ToString(); //这里获取到ID,已经测试输出sid的值为该行ID
string sql;
SqlConnection myconn;
SqlCommand mycommand;
myconn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbs"].ConnectionString);
sql = "select tname from users where id = '" + sid +"'" ;
mycommand = new SqlCommand(sql, myconn);
myconn.Open();
SqlDataReader aaa = mycommand.ExecuteReader();
Response.Write(aaa);
}
现在输出aaa的值无法输出,我很菜希望能帮忙。分数少见谅
其实你可以断点跟踪一下 SqlDataReader aaa = mycommand.ExecuteReader();
看aaa是什么,我想应为null;
sql = "select tname from users where id = '" + sid +"'" ;
改为:
sql = "select tname from users where id = '" + sid.Trim() +"'" ;
试试
要么你只有断点跟踪了。
aaa是一个sqldatareader对象,不能直接那样输出
protected void LinkButton1_Click(object sender, EventArgs e)
{
string sid;
sid = ((LinkButton)sender).CommandArgument.ToString(); //这里获取到ID,已经测试输出sid的值为该行ID
string sql;
SqlConnection myconn;
SqlCommand mycommand;
SqlDataReader aaa;
myconn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbs"].ConnectionString);
sql = "select tname from users where id = '" + sid +"'" ;
mycommand = new SqlCommand(sql, myconn);
myconn.Open();
aaa = mycommand.ExecuteReader();
While(aaa.Read())
{
Response.Write(aaa[i].ToString());
}
}