我想遍历每个数据行并检查 pid 的值,直到它得到 0 或 null 或空值...下面是我的代码
if (!string.IsNullOrEmpty(pIDstr))
{
int patientID = Convert.ToInt32(pID);
//string connection = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
string sqlquery = "SELECT * FROM [MyDatabase].[dbo].[PatExam] where PId = '" + patientID + "'";
string connection = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
using(SqlConnection conn = new SqlConnection(connection))
{
//SqlConnection conn = new SqlConnection(con);
DataSet ds;
ds = new DataSet();
SqlDataAdapter cmpatientexam;
conn.Open();
cmpatientexam = new SqlDataAdapter(sqlquery, conn);
cmpatientexam.Fill(ds, "PatientExam");
foreach (DataRow patrow in ds.Tables["PatientExam"].Rows)
{
TreeNode tvpatexam = new TreeNode();
tvpatexam.Text = patrow["PId"].ToString();
TreeView1.Nodes.Add(tvpatexam);
for //loop for checking all the patrow["PId"] value
{
TreeNode childtvpatexam = new TreeNode();
childtvpatexam.Text = patrow["Exam"].ToString();
tvpatexam.ChildNodes.Add(childtvpatexam);
}
//TreeView1.Nodes.Add(tvpatexam);
}
ds.Dispose();
cmpatientexam.Dispose();
conn.Close();
conn.Dispose();
}
}
这些怎么可能有人可以发送代码...非常感谢
我的数据库表 PatExam 包含以下值
PId Exam
1004 firstexam
1004 secondexam
1004 thridexam
1004 fourthexam
所以我希望 1004 作为我的父节点,并将 1004 的所有考试值作为树视图中的子节点....
怎么可能?