<pre lang="SQL">
YourTable
studentName Marks
Mark 100
Tisa 200
John 250
Michelle 150
Parker 450
Pete 50
Ben 400
Col 325
Mis 435
Aai 265
First Create a Procedure Like this
CREATE PROCEDURE [dbo].[usp_FetchRecord]
@UserEnteredValue int
AS
BEGIN
SET NOCOUNT ON;
SELECT TOP 1 studentName,Marks FROM YourTable
WHERE Marks>=@UserEnteredValue order by Marks asc
END
-- To run the Procedure, here user has enetered 200
--EXEC [dbo].[usp_FetchRecord] 200
Result
studentName Marks
Tisa 200
Code Behind on Button Click :
private void button1_Click(object sender, EventArgs e)
{
DataTable dttable = new DataTable();
using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["YourConnectionString"].ConnectionString))
using (var cmd = new SqlCommand("usp_FetchRecord", con))
using (var da = new SqlDataAdapter(cmd))
{
cmd.Parameters.AddWithValue("@UserEnteredValue", textBox1.Text);
cmd.CommandType = CommandType.StoredProcedure;
da.Fill(dttable);
}
}