0

これが私のコードです:

[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で使用するにはどうすればよいですか

4

1 に答える 1

1

ここに私が得た解決策があります

Web サービス コード

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;
}

Winform コード

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";
}
于 2013-03-07T19:36:07.333 に答える