CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2010
    Posts
    3

    WebMethod or DataSet doesn't work in Web Service

    I have a database with two tables in and I have created a dataset using both of the tables and created a query which is shown below...



    SELECT Stock_Info.Stock_Symbol, Stock_Info.Company_Name, Stock_Info.FTSE_Sector, Stock_Info.Country_Of_Share_Register, Stock_Info.ISIN_Number,
    Stock_Info.Stock, Price_Info.Stock_ID, Price_Info.Stock_Date, Price_Info.Price
    FROM Stock_Info INNER JOIN
    Price_Info ON Stock_Info.Stock_Symbol = Price_Info.Stock_Symbol
    WHERE (Stock_Info.Stock_Symbol = @Stock_Symbol)
    ORDER BY Stock_Info.Stock_Symbol, Price_Info.Stock_Date DESC



    and it works fine when I test it in the Query Builder, but then I created my WebMethod in my Web Service, which is this...



    [WebMethod]

    public void ViewPortfolio(string Stock_Symbol)

    {

    PortfolioDataSetTableAdapters.Stock_InfoTableAdapter portfolioTA =
    new PortfolioDataSetTableAdapters.Stock_InfoTableAdapter();

    if (!String.IsNullOrEmpty(Stock_Symbol))
    {
    portfolioTA.GetDataPortfolio(Stock_Symbol);
    }

    }



    and when I run my Web Service the WebMethod shows up as ViewPortfolio and I am able to click on it, but when I type in the Stock_Symbol the xml info that I want doesn't show up instead this text does...



    System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
    at System.Data.DataTable.EnableConstraints()
    at System.Data.DataTable.set_EnforceConstraints(Boolean value)
    at System.Data.DataTable.EndLoadData()
    at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
    at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
    at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
    at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
    at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
    at PortfolioDataSetTableAdapters.Stock_InfoTableAdapter.GetDataPortfolio(String Stock_Symbol) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\taskb\34b203b5\88af8b4e\App_Code.iu9j38-b.1.cs:line 998
    at QueryWebService.ViewPortfolio(String Stock_Symbol) in e:\Application Development 3\Assignment 2\TaskB\App_Code\QueryWebService.cs:line 51


    Can anybody please help me with this problem??

    Thank You

  2. #2
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: WebMethod or DataSet doesn't work in Web Service

    1) Use code tags around code
    2) Not enough information here for us to see what's going on. What is Stock_Symbol when it gets to this method? What does GetDataPortfolio do?

  3. #3
    Join Date
    Jan 2010
    Posts
    3

    Re: WebMethod or DataSet doesn't work in Web Service

    I have a database with two tables in called Stock_Info and Price_Info and I have created a dataset using both of the tables and created a query, which would get the information from the Stock table and the information in the Price table and match the Stock_Symbol to the one that is typed in and sort them in ascending order of Stock_Symbol and then in descending order of Stock_Date, my query is shown below...


    Code:
    SELECT Stock_Info.Stock_Symbol, Stock_Info.Company_Name, Stock_Info.FTSE_Sector, Stock_Info.Country_Of_Share_Register, Stock_Info.ISIN_Number, 
    Stock_Info.Stock, Price_Info.Stock_ID, Price_Info.Stock_Date, Price_Info.Price
    FROM Stock_Info INNER JOIN
    Price_Info ON Stock_Info.Stock_Symbol = Price_Info.Stock_Symbol
    WHERE (Stock_Info.Stock_Symbol = @Stock_Symbol)
    ORDER BY Stock_Info.Stock_Symbol, Price_Info.Stock_Date DESC

    This query works fine when I test it in the Query Builder, but then I created my WebMethod in my Web Service, which is this...


    Code:
    [WebMethod]
    
    public void ViewPortfolio(string Stock_Symbol)
    
    {
    
         PortfolioDataSetTableAdapters.Stock_InfoTableAdapter portfolioTA = 
         new PortfolioDataSetTableAdapters.Stock_InfoTableAdapter();
    
         if (!String.IsNullOrEmpty(Stock_Symbol))
         {
              portfolioTA.GetDataPortfolio(Stock_Symbol);
         }
    
    }


    When I run my Web Service the WebMethod shows up as ViewPortfolio and I am able to click on it and type in the Stock_Symbol that I want to see the information for but when I click on the invoke button to get my results the xml info that I want doesn't show up instead this text does...


    Code:
    System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
    at System.Data.DataTable.EnableConstraints()
    at System.Data.DataTable.set_EnforceConstraints(Boolean value)
    at System.Data.DataTable.EndLoadData()
    at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
    at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
    at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
    at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
    at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
    at PortfolioDataSetTableAdapters.Stock_InfoTableAdapter.GetDataPortfolio(String Stock_Symbol) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\taskb\34b203b5\88af8b4e\App_Code.iu9j38-b.1.cs:line 998
    at QueryWebService.ViewPortfolio(String Stock_Symbol) in e:\Application Development 3\Assignment 2\TaskB\App_Code\QueryWebService.cs:line 51

    Can anybody please help me with this problem??

    Thank You

  4. #4
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: WebMethod or DataSet doesn't work in Web Service

    Check the dataset for constraint set like uniques or string lenghts. I'm not sure if query builder really creates and fills the dataset, or just display raw data obtained from the database.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  5. #5
    Join Date
    Jan 2010
    Posts
    3

    Re: WebMethod or DataSet doesn't work in Web Service

    thanks for the reply, but i'm not very good with using web services and data sets etc so i'm not quite sure what you mean, could you please explain what i may need to do?
    thank you

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured