1.創建服務引用 例如:天氣預報 2.在代碼添加引用空間 1 TvProgram.ChinaTVprogramWebService tp = new TvProgram.ChinaTVprogramWebService(); 2 DataSet ds= tp.getAreaDataSet(); 3. ...
1.創建服務引用
例如:天氣預報
2.在代碼添加引用空間
1 TvProgram.ChinaTVprogramWebService tp = new TvProgram.ChinaTVprogramWebService(); 2 DataSet ds= tp.getAreaDataSet();View Code
3.引用具體方法
1 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) 2 { 3 ComboBox cb = (ComboBox)sender; 4 if(comboBox1.SelectedIndex>0) 5 { 6 7 int num= Convert.ToInt32(cb.SelectedValue.ToString()); 8 9 TvProgram.ChinaTVprogramWebService tp = new TvProgram.ChinaTVprogramWebService(); 10 DataSet ds = tp.getTVstationDataSet(num); 11 comboBox2.DataSource = ds.Tables[0]; 12 comboBox2.DisplayMember = "tvStationName"; 13 comboBox2.ValueMember = "tvStationID"; 14 15 } 16 }
返回的xml用兩種處理方法
//DataRow[] dt = ds.Tables[0].Select(); //for (int i = 3; i < dt.Length; i++) //{ // Text = dt[i]["Area"].ToString(); // Value = Convert.ToInt32(dt[i]["areaID"].ToString()); // comboBox1.Items.Add(Text); //}
comboBox1.DataSource = ds.Tables[0]; comboBox1.DisplayMember = "Area"; comboBox1.ValueMember = "areaID";