Skip to content

Values inserted by user and get records from data base

Ali Ashiq

Asked Feb 8, 2014, 12:18 AM EST7 answers
Share
LinkedInX
Hi, i have a two fields and want to get values from user and get products from data base my scenario is i have two text fields and on search button when a user press search button query pass to the database and get products against that query.
Here is my WebMethod  which will return products against user enter amount and person. Now same i want to do on my website please help me


public DataSet Restaurant(decimal amount, decimal persons)
    {
           decimal price = amount / persons ;
       DataSet result = null;
        const string SQL_COMMAND_TEXT = "SELECT Product_Name,Product_Price FROM       Table1234 WHERE Product_Price  <=  @price";
       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("@Persons", SqlDbType.NVarChar);
                command.Parameters.Add("@price", SqlDbType.SmallMoney);
                command.Parameters["@Rst_Name"].Value = amount;
                command.Parameters["@persons"].Value = persons;
                command.Parameters["@price"].Value = price;
                using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
                {
                    result = new DataSet();
                    dataAdapter.Fill(result);
                }
            }
        }

        return result;
    }

7 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Biswa Pujarini Mohapatra
    0
    Add the webservice to your web application by right click solution explore - add web reference - then call your webmthod in your aspx page
    0
  • 0
    mam i have done with add web reference what is the next step
    0
  • 0
    Mam i have googled a lot but it all goes over my head:'( how could i do this i am totally fed up
    0
  • 0
    Mam i need your help now i get to now how to call web service methods into an aspx page. using j query in the current block where we want to show content against method called. Now i have wasted whole day to know about this, now i need your help how could i do this on my Default.aspx page where i put j query/Java script please help me i have to submit my project on monday and i need your help
    0
  • Biswa Pujarini Mohapatra
    0
    step : top of your webmethod class decorate attribute as
    Code
    using System.Web.Script.Serialization; using System.Web.Script.Services;
    [System.Web.Script.Services.ScriptService]     
    public class WebService1 : System.Web.Services.WebService
    {
    [WebMethod]
    [ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
    C#
    public DataSet Restaurant(decimal amount, decimal persons)
        {
               decimal price = amount / persons ;
           DataSet result = null;
            const string SQL_COMMAND_TEXT = "SELECT Product_Name,Product_Price FROM       Table1234 WHERE Product_Price  <=  @price";
           using (SqlConnection connection = Class1.GetConnection())
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(SQL_COMMAND_TEXT, connection))
                {
    
                    command.Parameters["@price"].Value = price;
                    using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
                    {
                        result = new DataSet();
                        dataAdapter.Fill(result);
                    }
                }
            }
    
    
            return result;
        }

    }

    step 2 -<script type="text/javascript" src="script/jquery-1.2.6.min.js"></script>

    <script type="text/javascript">

     

      function getRestuarants() {

        $.ajax({

          type: "POST",

          url: "WebService.asmx/Restaurant",

          data: "{amount: " + $('#<%= txtprice.ClientID %>').val() + " , persons: " + $('#<%= txtpersons.ClientID %>').val() + "}",

          contentType: "application/json; charset=utf-8",

          dataType: "json",

          success: function(response) {

           //do things  bind your drop down

    Code
            }

        });

      }

    </script>


    0
  • 0
     data: "{amount: " + $('#<%= txtprice.ClientID %>').val() + " , persons: " + $('#<%= txtpersons.ClientID %>').val() + "}",

    Mam i got error on this portion it goes over my head:'( will you please define this thing 
    0
  • 0
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="DefaultLogin" %>

    <!DOCTYPE html>
       
        
        
       
       
       
       
           
                   
           
               
       


    i know its a textbox id but still i am getting error.
    0