Select * From HumanResources.Department where DepartmentID = @id.
// Web Service > >using System; >using System.Data; >using System.Web; >using System.Collections; >using System.Web.Services; >using System.Web.Services.Protocols; >using System.ComponentModel; > >namespace wsAwDept >{ > /// <summary> > /// Summary description for svcAwDept > /// </summary> > [WebService(Namespace = "http://catsnjazz/")] > [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] > [ToolboxItem(false)] > public class svcAwDept : System.Web.Services.WebService > { > > [WebMethod(Description = "Returns a dataset according to desired id")] > public DataSet GetDeptById(short id) > { > // create dataset (ds), datatable (dt) and table adapter (adapter) > dsDept ds = new dsDept(); > dsDept.DepartmentDataTable dt = new dsDept.DepartmentDataTable(ds.Tables[0]); > dsDeptTableAdapters.DepartmentTableAdapter adapter = > new dsDeptTableAdapters.DepartmentTableAdapter(); > > // call adapter method to fill datatable according to requested id > adapter.FillByID(dt, id); > > return ds; > } > } >}>
// Calling program > >using System; >using System.Collections.Generic; >using System.ComponentModel; >using System.Data; >using System.Drawing; >using System.Text; >using System.Windows.Forms; > >namespace awdatatest >{ > public partial class Form1 : Form > { > // create service, dataset and datatablereader > catsnjazz.svcAwDept ws = new catsnjazz.svcAwDept(); > DataSet departmentDS = new DataSet(); > DataTableReader dr; > > public Form1() > { > InitializeComponent(); > } > > private void btnStart_Click(object sender, EventArgs e) > { > // create a dataset using service and id of 11 > departmentDS = ws.GetDeptById(11); > // set the datatablereader to the table in the dataset > dr = departmentDS.CreateDataReader(departmentDS.Tables[0]); > > // see if we have the right table > MessageBox.Show(dr.GetName(0) + "\r\n" + > dr.GetName(1) + "\r\n" + > dr.GetName(2) + "\r\n" + > dr.GetName(3)); > > if (dr.HasRows) > { > // move to 1st record and display the data > dr.Read(); > this.showData(dr); > } > else > { > // no data in the dataset - WHY NOT?? > MessageBox.Show("No rows returned"); > } > } > > // display the data in the dataset > private void showData(DataTableReader dr) > { > MessageBox.Show(dr.GetValue(0).ToString() + "\r\n" + > dr.GetValue(1).ToString() + "\r\n" + > dr.GetValue(2).ToString() + "\r\n" + > dr.GetValue(3).ToString()); > } > } >}I see one thing.
dsDept.DepartmentDataTable dt = new dsDept.DepartmentDataTable(ds.Tables[0]);
You are creating a "new" table outside of your dataset, so your dataset will be empty if you fill that table. (The table will have data, but you are returning the dataset, not the table.)dsDept.DepartmentDataTable dt = ds.DepartmentDataTable;or
adapter.FillByID(ds.DepartmentDataTable, id);HTH