此代码仅添加第一行,如何添加“mail”列的第二行
var cs = ConfigurationManager.ConnectionStrings["ConnectionString"];
var sc = new SqlConnection(cs.ConnectionString);
sc.Open();
string str = "Select * From [Table1]";
var cmd = new SqlCommand(str, sc);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
ListBox1.Items.Add(dr["mail"].ToString());
}
sc.Close();
答案 0 :(得分:0)
if (dr.HasRows)
{
while (dr.Read())
{
/* your code */
}
}
else
{
/* error message */
}