Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Datasets and Web Services

Datasets and Web Services

Scheduled Pinned Locked Moved C#
databasesql-serverwcfsysadminwindows-admin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ronin1770
    wrote on last edited by
    #1

    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

    K 1 Reply Last reply
    0
    • R ronin1770

      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

      K Offline
      K Offline
      Kodanda Pani
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups