I'm using SqlDataSource to populate a GridView. Here is my code that does that :
private void DataCall()
{
//Object gets created for use from the class(clsDataConduit)
clsDataDictionary AnOrder = new clsDataDictionary();
//Declaring a new SqlDataSource from the inbuilt class library
SqlDataSource sqlDS_ItemTable = new SqlDataSource();
//Using our datasource object being cast onto our objects connectionstring
sqlDS_ItemTable.ConnectionString = AnOrder.ConnectionString;
//Our sql statement being passed through to our .SelectCommand method
sqlDS_ItemTable.SelectCommand = "Select tblOrders.OrderId, tblItem.ItemName, tblOrders.DateOrdered from tblItem, tblOrders where tblItem.ItemId = tblOrders.ItemId AND tblOrders.AuthId = 5";
//Adding controls to our SqlDataSource object
this.Controls.Add(sqlDS_ItemTable);
//Declares the DataSource for our gridview !
grdOrder.DataSource = sqlDS_ItemTable;
//Binds the data to refresh every time it's used
grdOrder.DataBind();
}
As you can see in the SQL statement at the end i'm doing this tblOrders.AuthId = 5 . However I want to do something like this tblOrders.AuthId = SessionAuthId .
I read some posts about doing something alone the lines of command.Parameters.Add(new SqlParameter("Name", dogName)); but I don't know how I apply this to my code.
I'm doing this in an assignment using someone elses code (professors) but I want to edit it slightly because i'm going to be developping a login system etc.
Could someone take a look at that method and see how I would change it to pass the parameter to it. Also here is the full code behind : http://pastebin.com/sdrvW5Zn