Monday, March 8, 2010

Populate GridView using stored proc. Sql-server C#

 Populate GridView using stored proc. Sql-server  C#, input from screen textbox.
 
 
private void PopulateGridView()

{

Button1.Visible = true;

Button3.Visible = true;

SqlConnection myConnection = new SqlConnection(ConnectionString);

String strSQL;

String strOwner;

strOwner = DropDownList1.SelectedItem.Text;

if (strOwner == "*" || strOwner == "")

{

strSQL = "ovfinrepFULL '" + TextBox1.Text + "' , '" + TextBox2.Text + "'";

}

else

{

strSQL =

"ovfinrepFULL '" + TextBox1.Text + "' , '" + TextBox2.Text + "','" + DropDownList1.SelectedItem.Text + "'";

}

//Response.Write(strSQL);

//Response.End();

SqlDataAdapter ad = new SqlDataAdapter(strSQL, myConnection);

DataSet ds = new DataSet();

ad.Fill(ds);

MyGridView.DataSource = ds;

MyGridView.DataBind();

}

No comments: