private void FormZT_Load(object sender, EventArgs e)
{
comboBoxzt.Focus();
DataGn gn = new DataGn();
string s="";
s = gn.zcb() + "fterp";
try
{
SqlConnection myConn = new SqlConnection(s);
myConn.Open();
SqlCommand myCmd = new SqlCommand("select * from tb_zt", myConn);
SqlDataReader myRead = myCmd.ExecuteReader();
if (myRead.HasRows)
{
while (myRead.Read())
{
comboBoxzt.Items.Add(myRead[0].ToString() + "(" + myRead[1].ToString() + ")");
}
}
myRead.Close();
myConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);//运行后总是循环出现错误提示
}
}
{
comboBoxzt.Focus();
DataGn gn = new DataGn();
string s="";
s = gn.zcb() + "fterp";
try
{
SqlConnection myConn = new SqlConnection(s);
myConn.Open();
SqlCommand myCmd = new SqlCommand("select * from tb_zt", myConn);
SqlDataReader myRead = myCmd.ExecuteReader();
if (myRead.HasRows)
{
while (myRead.Read())
{
comboBoxzt.Items.Add(myRead[0].ToString() + "(" + myRead[1].ToString() + ")");
}
}
myRead.Close();
myConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);//运行后总是循环出现错误提示
}
}
如果是循环出错的话,那就说明:
while (myRead.Read())
{
comboBoxzt.Items.Add(myRead[0].ToString() + "(" + myRead[1].ToString() + ")");
}
这里有问题