Ali Ashiq

Ali Ashiq

  • NA
  • 61
  • 32.3k

Values inserted by user and get records from data base

Feb 8 2014 5:18 AM
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;
    }

Answers (7)