Datasets and Web Services
-
HI, I am trying to build a simple web services which simply get list of employee's last name from Sql server's database. The method in web-service class is supposed to read the data from the db and return the results in a form of DataSet and it is defined as : --------------------------------------- //a web method which retrieves data (last names of about given //thing in form of a data set [WebMethod(BufferResponse=true)] public DataSet getLastNames() { //string var representing sql string string sql = ""; //create a new temp dataset DataSet ds = new DataSet(); try { //open the connection scConn.Open(); //create the sql sql = "SELECT LastName FROM tblEmployees"; //create the command cmd = new SqlCommand(sql,scConn); //create the sql data adapter SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(ds,"Employees"); Console.WriteLine(ds.Tables.Count); //clean up code sda=null; cmd=null; scConn.Close(); return ds; } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } ---------------------------------------------------- I want to display the data from the dataset in a DataGrid (in a Windows Form) in a DataGrid. Window form also contains one button which calls webmethod and fills out datagrid. The code is given as : --------------------------- private void cmdConnect_Click(object sender, System.EventArgs e) { try { DataSet ds = new DataSet(); localhost.wsEmployees ws = new wsEmployeesClient.localhost.wsEmployees(); ds = ws.getLastNames(); Console.WriteLine(ds.Tables[0].Rows); } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } ------------------------------ note localhost = name of web reference ----------------------------------- Problem : No records can be found. There is no table in dataset. I just want to know what i am doing WRONG. Am I missing out something either in code or IIS Server's Administration. thanx in advance
-
HI, I am trying to build a simple web services which simply get list of employee's last name from Sql server's database. The method in web-service class is supposed to read the data from the db and return the results in a form of DataSet and it is defined as : --------------------------------------- //a web method which retrieves data (last names of about given //thing in form of a data set [WebMethod(BufferResponse=true)] public DataSet getLastNames() { //string var representing sql string string sql = ""; //create a new temp dataset DataSet ds = new DataSet(); try { //open the connection scConn.Open(); //create the sql sql = "SELECT LastName FROM tblEmployees"; //create the command cmd = new SqlCommand(sql,scConn); //create the sql data adapter SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(ds,"Employees"); Console.WriteLine(ds.Tables.Count); //clean up code sda=null; cmd=null; scConn.Close(); return ds; } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } ---------------------------------------------------- I want to display the data from the dataset in a DataGrid (in a Windows Form) in a DataGrid. Window form also contains one button which calls webmethod and fills out datagrid. The code is given as : --------------------------- private void cmdConnect_Click(object sender, System.EventArgs e) { try { DataSet ds = new DataSet(); localhost.wsEmployees ws = new wsEmployeesClient.localhost.wsEmployees(); ds = ws.getLastNames(); Console.WriteLine(ds.Tables[0].Rows); } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } ------------------------------ note localhost = name of web reference ----------------------------------- Problem : No records can be found. There is no table in dataset. I just want to know what i am doing WRONG. Am I missing out something either in code or IIS Server's Administration. thanx in advance
Hi, Looks like the code is ok. Try running the webservice alone and see what output you are getting. There may be some problem in accessing the database itself. Regards SGS