protected void Button1_Click(object sender, EventArgs e)
{
RadGrid1.DataSource = RunStoredProcSearch(
"SearchNameCity", SearchGrid.Text);
RadGrid1.DataBind();
}
public DataSet RunStoredProcSearch(string spName, string search)
{
SqlConnection conn = null;
SqlDataReader rdr = null;
try
{
// create and open a connection object
conn =
new
SqlConnection("Data Source=LDSERVER1\\SQLLD;Initial Catalog=AviarySQL;Integrated Security=True");
conn.Open();
// 1. create a command object identifying
// the stored procedure
SqlCommand cmd = new SqlCommand(
spName, conn);
// 2. set the command object so it knows
// to execute a stored procedure
cmd.CommandType =
CommandType.StoredProcedure;
// 3. add parameter to command, which
// will be passed to the stored procedure
cmd.Parameters.Add(
new SqlParameter("@pattern", search));
// execute the command
cmd.Connection.Open();
SqlDataReader reader = cmd.ExecuteReader();
return reader;
}
finally
{
if (conn != null)
{
conn.Close();
}
if (reader != null)
{
rdr.Close();
}
}
}