【发布时间】:2011-08-13 06:21:46
【问题描述】:
我需要执行以下命令并将结果传递给标签。我不知道如何使用 Reader 来做到这一点。有人可以帮帮我吗?
String sql = "SELECT * FROM learer WHERE learer.id = " + index;
SqlCommand cmd = new SqlCommand(sql,conn);
learerLabel.Text = (String) cmd.ExecuteReader();
如您所见,我创建了 SQL 语句并执行了它,但它不起作用。为什么?
控制台说:
不能隐式 SqlDataReader 到 字符串...
我怎样才能得到想要的结果作为字符串,以便标签可以正确显示它。
【问题讨论】:
-
你的代码容易被sql注入
-
Using select count(*) in c# 的可能重复项