想请教一下这是什么问题,班级能显示出来,别的显示不出来
private void 申请调宿ToolStripMenuItem_Click(object sender, EventArgs e)
{
//清除原有控件
splitContainer.Panel1.Controls.Clear();
//splitContainer.Panel2.Controls.Clear();
try
{
//打开数据库
string constr = "data source=192.168.1.197; " +
"Database=Dormitory;" +
"user id=sa; " +
"password=HandQuite229";
conn = new SqlConnection(constr);
conn.Open();
//创建命令
cmd = new SqlCommand();
cmd.Connection = conn;
string cmdStr = string.Format("select * from student where sNumber = '{0}'", sNumber);
cmd.CommandText = cmdStr;
Console.WriteLine(cmdStr);
//查询
sdAdapetr = new SqlDataAdapter();
sdAdapetr.SelectCommand = cmd;
DataSet dataSet = new DataSet();
sdAdapetr.Fill(dataSet);
sMajorClass = dataSet.Tables[0].Rows[0]["sMajorClass"].ToString();
sPhone = dataSet.Tables[0].Rows[0]["sPhone"].ToString();
sBed = dataSet.Tables[0].Rows[0]["sBed"].ToString();
conn.Close();
Console.WriteLine(sMajorClass + "--" + sBed + "--" + sPhone);
}
catch (Exception error)
{
if (conn.State.ToString() == "Open")
conn.Close();
MessageBox.Show(error.Message.ToString());
}
Point p1 = new Point(splitContainer.Panel1.Left,
splitContainer.Panel1.Top);
Label name_label = new Label();
name_label.Text = string.Format("姓名:{0}", sName);
name_label.Location = new Point(p1.X + 10, p1.Y + 20);
Label class_label = new Label();
class_label.Text = string.Format("班级:{0}", sMajorClass);
class_label.Location = new Point(p1.X + 10, name_label.Location.Y + 40);
Label sNumber_label = new Label();
sNumber_label.Text = string.Format("学号:{0}", sNumber);
sNumber_label.Location = new Point(p1.X + 10, class_label.Location.Y + 40);
Label sPhone_label = new Label();
sPhone_label.Text = string.Format("联系方式:{0}", sPhone);
sPhone_label.Size = new Size(100, 20);
sPhone_label.Location = new Point(p1.X + 10, sNumber_label.Location.Y + 40);
Label sBed_label = new Label();
sBed_label.Text = string.Format("原床位:{0}", sBed);
sBed_label.Location = new Point(p1.X + 10, sPhone_label.Location.Y + 40);
Label sTargetBed_label = new Label();
sTargetBed_label.Text = string.Format("目标床位:");
sTargetBed_label.Location = new Point(p1.X + 10, sBed_label.Location.Y + 40);
sTargetBed_label.Size = new Size(70, 20);
TextBox sTargetBed_tbox = new TextBox();
sTargetBed_tbox.Location = new Point(p1.X + 10 + 70,
sBed_label.Location.Y + 40);
sTargetBed_tbox.Size = new Size(splitContainer.Panel1.Width - 100, 20);
label23.Text = string.Format("联系方式:{0}", sPhone);
splitContainer.Panel1.Controls.Add(name_label);
splitContainer.Panel1.Controls.Add(class_label);
splitContainer.Panel1.Controls.Add(sNumber_label);
splitContainer.Panel1.Controls.Add(sPhone_label);
splitContainer.Panel1.Controls.Add(sBed_label);
splitContainer.Panel1.Controls.Add(sTargetBed_label);
splitContainer.Panel1.Controls.Add(sTargetBed_tbox);
}