Reputation: 120
Here Is My Code :
[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();
}
now what to do to return the data and use in my winform
Upvotes: 0
Views: 2730
Reputation: 120
Here is the Solution i Got
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";
}
Upvotes: 1