这是我的代码:
[WebMethod]
public SqlDataReader Cmb_BranchMaster() {
SqlCommand ad1 = new SqlCommand("select * from BranchMaster", conn);
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Open();
SqlDataReader rdr2 = ad1.ExecuteReader();
if (rdr2.HasRows)
{
while (rdr2.Read())
{
// here cmbranchname is my combobox of winforms .. so here in webservice it gievs error
cmbBranchName.Items.Add(rdr2[1].ToString());
}
}
conn.Close();
}
现在该做什么来返回数据并在我的winform中使用
答案 0 :(得分:1)
这是我得到的解决方案
static SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"].ToString());
[WebMethod]
public DataSet Cmb_BranchMaster()
{
conn.Open();
SqlCommand ad1 = new SqlCommand("select * from BranchMaster", conn);
SqlDataAdapter adapt = new SqlDataAdapter(ad1);
DataSet ds = new DataSet();
adapt.Fill(ds);
conn.Close();
return ds;
}
private void ComboBox_Load(object sender, EventArgs e)
{
myservice.Service test = new myservice.Service();
DataSet dd = new DataSet();
dd = test.Cmb_BranchMaster();
comboBox1.DataSource = dd.Tables[0];
comboBox1.DisplayMember = "BranchName";
comboBox1.ValueMember = "BranchID";
}