Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my Database diagram and my scenario is that When a user enter number of person and amount, amount/person
let suppose 4/1000=250 and now 250 is , match in Product_Price Field in RstProductDetails, and select only Restaurant where 250 is matched. Next when a user select Restaurant e.g KFC and then KFC Products details is show.
Here is my [WebMethod]
C#
    [WebMethod]
    public DataSet Restaurant(string Amount, string PersonHash)
    {
//        DataSet result = Amount / personHash;

        DataSet result = null;
        const string SQL_COMMAND_TEXT = "SELECT Rst_Name FROM RstProductDetails WHERE Product_Name WHERE Product_rice<=250 = @Rst_Name";
        using (SqlConnection connection = Class1.GetConnection())
        {
            connection.Open();
            using (SqlCommand command = new SqlCommand(SQL_COMMAND_TEXT, connection))
            {
                command.Parameters.Add("@Rst_Name", SqlDbType.NVarChar);
                command.Parameters.Add("@PersonHash", SqlDbType.NVarChar);
                command.Parameters["@Rst_Name"].Value = Amount;
                command.Parameters["@PersonHash"].Value = PersonHash;
                using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
                {
                    result = new DataSet();
                    dataAdapter.Fill(result);
                }
            }
        }

        return result;
    }
Posted
Updated 1-Feb-14 5:03am
v2
Comments
Madhav Hatwalne 1-Feb-14 10:42am    
your question is not clear kindly elaborate it!!
Ali Ashiq 1-Feb-14 10:48am    
i want to access records against query that is SELECT RstName FROM RstProductDetails, and my scenario is that i want to take input from user thats is Person and Amount. Amount is going to be divide by Person and the result is going to match in RstProductDetails
Ali Ashiq 1-Feb-14 10:51am    
Lets suppose if a user ENTER 1000 Amount and 4Person, 1000/4=250. Now 250 is pass and match from the Product_Price in RstProductDetails, and show restaurant which have product having price 250

1 solution

Ok it's very simple your function is accepting 2 parameters 1) Amount 2) Person
in your function calculate amount
C#
decimal price = amount \ persons

and this price as parameter

C#
WHERE Product_rice< = @price";

command.Parameters.Add("@price", SqlDbType.Decimal);


C#
command.Parameters["@price"].Value = price;
 
Share this answer
 
v3
Comments
Ali Ashiq 1-Feb-14 11:18am    
Error 5 Cannot implicitly convert type 'string' to 'decimal'
Error 6 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
Error 7 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
here is the errors
Ali Ashiq 1-Feb-14 11:20am    
I have also post this question on http://social.technet.microsoft.com/Forums/sqlserver/en-US/7ba0dadc-00d1-43a8-b923-0e2c16d5dde4/how-to-get-records-from-different-tables-using-webservices?forum=databasedesign

Here is my database diagram
Madhav Hatwalne 2-Feb-14 7:57am    
always remember these points while posting any question
1) Get yourself trained in technology
2) Improve your logic
3) do simple google
4) ask seniors(if exists)
4) when any one is giving you answer he is giving you idea .. don't blindly copy paste
Madhav Hatwalne 2-Feb-14 8:05am    
you have to do simple changes is your code it will work but you have to apply your logic
Ali Ashiq 2-Feb-14 8:43am    
ohh Sorry sir it was my mistake and i have resolve it already at that time, web services is working properly but when i debug it will give me eror
System.IndexOutOfRangeException: An SqlParameter with ParameterName '@persons' is not contained by this SqlParameterCollection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900