Yes, its for checking duplicates. It works fine, HOWEVER, I have the thing inside an AJAX UpdatePanel, and I get a "@PCluster is already declared" kind of error. Im suspecting that since I dont get a full postback, the variable doesnt get cleared/renewed.
How do I manually remove/clear a variable manually?
On full postback, it does ok. But if inside an UpdatePanel, I get an error: "The Variable Name @PCluster has already been declared. Variable names mus be unique whithin a query batch or stored procedure"
wreck_of_u
Member
224 Points
119 Posts
Clearing/Removing a variable
Jul 04, 2007 07:22 AM|LINK
Hi I have this code
if (txtNewClusterName.Text != ""){
//check if a duplicate exists Parameter PCluster = new Parameter();PCluster.Name =
"PCluster"; PCluster.Type = TypeCode.String;PCluster.DefaultValue = txtNewClusterName.Text;
SqlDataSource SqlDS_ClusterValidate = new SqlDataSource(); this.Controls.Add(SqlDS_ClusterValidate); SqlDS_ClusterValidate.ID = "SqlDS_ClusterValidate";SqlDS_ClusterValidate.ConnectionString =
"my connection string here"; SqlDS_ClusterValidate.SelectCommand = "SELECT [ClusterName] FROM [myClusterTable] WHERE ([ClusterName] = @PCluster)";SqlDS_ClusterValidate.SelectParameters.Add(PCluster);
SqlDS_ClusterValidate.SelectCommandType = SqlDataSourceCommandType.Text;
GridView gvClusterValidate = new GridView();gvClusterValidate.DataSource = SqlDS_ClusterValidate;
gvClusterValidate.DataBind();
if ((gvClusterValidate.Rows.Count != 0)){
lblError.Text = "Cluster already exists!";}
else{
SQLDS_Cluster.Insert();
lblError.Text = "";}
}
Yes, its for checking duplicates. It works fine, HOWEVER, I have the thing inside an AJAX UpdatePanel, and I get a "@PCluster is already declared" kind of error. Im suspecting that since I dont get a full postback, the variable doesnt get cleared/renewed.
How do I manually remove/clear a variable manually?
codeasp
Star
14735 Points
2545 Posts
Re: Clearing/Removing a variable
Jul 04, 2007 08:05 AM|LINK
if (txtNewClusterName.Text != "") { // Clear the old message if any lblError.Text = "" // Now start checking for duplicates }kipo
All-Star
16475 Points
2811 Posts
Re: Clearing/Removing a variable
Jul 04, 2007 08:08 AM|LINK
Try with this:
wreck_of_u
Member
224 Points
119 Posts
Re: Clearing/Removing a variable
Jul 04, 2007 08:17 AM|LINK
Hi, im having trouble with this one:
Parameter PCluster = new Parameter();
PCluster.Name = "PCluster"
On full postback, it does ok. But if inside an UpdatePanel, I get an error: "The Variable Name @PCluster has already been declared. Variable names mus be unique whithin a query batch or stored procedure"
wreck_of_u
Member
224 Points
119 Posts
Re: Clearing/Removing a variable
Jul 04, 2007 08:19 AM|LINK
Thank you! Worked like a charm.
kipo
All-Star
16475 Points
2811 Posts
Re: Clearing/Removing a variable
Jul 04, 2007 08:36 AM|LINK
I'm glad I helped you, but you should try to use this code instead of your: