View Single Post
Old 01-18-2013, 12:53 PM   PM User | #4
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
sql
Code:
create proc usp_myDemo
    @Surname varchar()
AS

SELECT [fieldA], [fieldB], ... [fieldN]
FROM tbl_Demo
WHERE [SURNAME] = @Surname

somewhere in aspx page
Code:
<asp:TextBox runat="server" ID=txtSur></asp:TextBox>
............
<asp:GridView runat="server" ID=gr></asp:GridView>
somewhere in C#
Code:
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(cnstr);
using(conn)
{
  SqlCommand cmd = new SqlCommand("usp_myDemo", conn);
  using(cmd)
  {
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.Add(new SqlParameter("@Surname", txtSur.Text));
    // note this string is not cleaned- you need to clean it first 
    conn.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    dt.Load(dr);
    conn.Close();
   }
}

gr.DataSource = dt;
gr.DataBind();
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote