|
I use SqlDataSource to bind to GridView. Because the Select in my SqlDataSource is dynamic. For example: select a, b, c from xxx, sometimes: select b, c from xxx
sqlstr is the SQL statement I generated:
sqlstr = "Select aa, bb From Guest WHERE (PublicName = @PublicName) AND (PType = @PType)"
DefineTypeDS is SqlDataSource, which is a SqlDataSource control that I dragged in the design page. The name is DefineTypeDS.
DefineTypeDS.SelectCommand = sqlstr;
DefineTypeDS .SelectParameters .Clear ();
DefineTypeDS.SelectParameters.Add (new Parameter ("@PublicName", TypeCode.String));
DefineTypeDS.SelectParameters.Add ("@ PType", "");
DefineTypeDS.SelectParameters ["@ PublicName"]. DefaultValue = "username";
DefineTypeDS.SelectParameters ["@ PType"]. DefaultValue = "newguest";
// When the program is executed here, an error is reported: the variable '@PublicName' must be declared
DefineTypeDS.Select (DataSourceSelectArguments.Empty);]
Puzzled! Please master help. Thank you! !! |
|