this example is return GGYY's array from SQL
----------------------------------------------------------------------------------------
public GGYY[] GetGGYY() {
string sql = @"SELECT xxxxxxxxxxxxx";
List<GGYY> GGYYList = new List<GGYY>();
string connectString = ConfigurationManager.ConnectionStrings["GivenConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connectString);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
try {
SqlDataReader r = cmd.ExecuteReader();
while (r.Read()) {
GGYY item = new GGYY();
item.id = (int)r["ID"];
item.gg = r["gg"].ToString();
item.yy =r["yy"].ToString();
GGYYList.Add(item);
}
r.Close();
} catch (Exception e) {
}
conn.Close();
return GGYYList.ToArray();
}
----------------------------------------------------------------------------------------
string sql = @"SELECT xxxxxxxxxxxxx";
List<GGYY> GGYYList = new List<GGYY>();
string connectString = ConfigurationManager.ConnectionStrings["GivenConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connectString);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
try {
SqlDataReader r = cmd.ExecuteReader();
while (r.Read()) {
GGYY item = new GGYY();
item.id = (int)r["ID"];
item.gg = r["gg"].ToString();
item.yy =r["yy"].ToString();
GGYYList.Add(item);
}
r.Close();
} catch (Exception e) {
}
conn.Close();
return GGYYList.ToArray();
}
沒有留言:
發佈留言