Paul Arthur

Paul Arthur

  • NA
  • 12
  • 3.1k

Remove Parameters

Nov 23 2015 8:45 AM
Hi,
 
I need some help. I am really new to C# and have to do something in ASP.NET to get data from SQL Server and display it in a GridView.
 
I have been able to populate the GridView but now I have come to a block because I need the user to be able to edit the data. On the RowEditing part of the code I am using the same databind() which is the same for loading the inital data into the GridView. 
 
I come across this error message;
The variable name '@Year1' has already been declared.
 
Can someone please tell me how to drop the parameters. I have tired
myCommand.Parameters.Clear();
 
 
public void binddata()
{
//My Databind
SqlDataSource SqlDataSource1 = new SqlDataSource();
SqlDataSource1.ID = "SqlDataSource1";
this.Page.Controls.Add(SqlDataSource1);
SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["RMUConnectionString"].ConnectionString;
SqlDataSource1.SelectCommand = @"SELECT
base.[Contract Number] AS Contract_Number,
base.[Lead PCT] AS LeadPCT,
base.[BMI Site] AS BMISite,
base.[CQUIN Indicator] AS CQUIN_Indicator,
base.[Original Indicator Weighting (% of total Scheme)] AS IndicatorPer,
base.odscode AS ODS,
[Achievement Reported by site (% of individual indicator)] / 100 AS Achievement,
[Agreed by CCG] AS Agreed
FROM [CQUIN BASE DATA] base
LEFT JOIN [CQUIN DATA TABLE] A
ON base.odscode = a.odscode
AND base.[Contract Number] = a.[Contract Number]
AND base.[CQUIN Indicator] = a.[CQUIN Indicator]
AND a.Quarter = @Year1 + ' ' + @Quarter1
AND a.Date_Updated = (SELECT
MAX(date_updated)
FROM [CQUIN DATA TABLE] a2
WHERE a2.odscode = a.odscode
AND a2.[Contract Number] = a.[Contract Number]
AND a2.[CQUIN Indicator] = a.[CQUIN Indicator]
AND a2.quarter = a.quarter)
WHERE base.[Contract Number] = @Contract1
AND base.odscode = @Site1
AND base.Quarter = RIGHT(RTRIM(@Quarter1), 1)
ORDER BY 1, 3, 4";
//Declare Parameters
SqlDataSource1.SelectParameters.Add("Year1", TextYear.SelectedValue);
SqlDataSource1.SelectParameters.Add("Site1", TextSite.SelectedValue);
SqlDataSource1.SelectParameters.Add("Contract1", TextContract.SelectedValue);
SqlDataSource1.SelectParameters.Add("Quarter1", TextQuarter.SelectedValue);
MainDataView.DataSource = SqlDataSource1;
MainDataView.DataBind();
}
 
Any help would be great.
 
Paul 
 

Answers (7)