我只想在設計中的標籤中的通用列表中顯示學生的詳細信息。顯示標籤中的通用列表項目
我在foreach循環中收到錯誤x is not in the current context
。
namespace gentask
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=Sadiq;Initial Catalog=rafi;Integrated Security=True";
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from student";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
}
}
public class student
{
student std;
List<student> stud = new List<student>();
public void load()
{
foreach (DataRow dr in x)
{
std = new stud();
std.id = x[0].Tostring();
std.name = x[1].Tostring();
std.age = x[2].Tostring();
std.school = x[3].Tostring();
std.clas = x[4].Tostring();
std.marks = x[5].Tostring();
std.grade = x[6].Tostring();
stud.Add(std);
}
}
public void show()
{
foreach (student std in stud)
{
std.id = label.text;
std.name = label1.text;
std.age = label2.text;
std.school = label3.text;
std.clas = label4.text;
std.marks = label5.text;
std.grade = Label6.Text;
}
}
}
}
'的foreach(在X的DataRow博士)' - 這裏是'x'定義 – Tim
你真的應該開始更慢你知道如何在實驗室中顯示_anything_?埃爾?像數字「42」?先嚐試一下。 –