//从数据库里读出SqlDataReader
public static SqlDataReader ExecuteReader(string strSQL)
{
//链接数据库的操作
SqlConnection connection = new SqlConnection(connectionString);SqlCommand cmd = new SqlCommand(strSQL, connection);
try
{
connection.Open();
SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return myReader;
}
catch (System.Data.SqlClient.SqlException e)
{
throw e;
}
}
//运用数据库中ExecuteReader得到相应的SqlDataReader
public SqlDataReader getcombo(string xx)
{
StringBuilder strsql = new StringBuilder();
strsql.Append("SELECT ");
strsql.Append(xx);
strsql.Append(" FROM tb_SpecialtyInfo");
//string strsql= "SELECT Specialtyid FROM tb_SpecialtyInfo";
return DbHelperSQL.ExecuteReader(strsql.ToString());
}
//在winform端得到SqlDataReader,然后将那一列数据加入combobox中
SqlDataReader read = bll.getcombo("Specialtymc");
if (read.HasRows)
{
while (read.Read())
{
//下面是将tb_SpecialtyInfo中的Specialtymc列数据一个个加入combobox中
comboBox1.Items.Add(read["Specialtymc"].ToString());
}
}