本帖最后由 包连靖 于 2012-4-16 16:25 编辑
using ( SqlConnection conn = new SqlConnection( @"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\chengshi.mdf;Integrated Security=True;User Instance=True")) { conn.Open(); //连??接??数?y据Y库a,然??后??打???开a using (SqlCommand cmd = conn.CreateCommand()) //执??行D数?y据Y库a语??句? { cmd.CommandText = "select * from promary" ;//选?择?所??有?D的??省?? using (SqlDataReader datereader = cmd.ExecuteReader()) //读??取??行D:定??义??datereader去???执??行D读??取?? { while (datereader.Read())//循-环??-阅?读??每?一??行D语??句? { province items = new province(); //province类???的??实???例?y化?? //datereader来???执??行D获?取??string类???型??(从???proName这a个?里??面?获?取??) items.name = datereader.GetString(datereader.GetOrdinal( "proName" )); //同??理??? items.id = datereader.GetInt32(datereader.GetOrdinal( "proID" ));
cmbpro.Items.Add(items); //让??栏??里??面?输??出?items,不?过y一??开a始??改?成??了??name的??所??以??只?输??出?name
} } } } Form1_Load里面的
|