| |

VerySource

 Forgot password?
 Register
Search
View: 794|Reply: 8

"Novice" SqlDataSource dynamic setting problem! Thank you! !!

[Copy link]

2

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-8 23:20:01
| Show all posts |Read mode
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! !!
Reply

Use magic Report

2

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-1-21 11:45:02
| Show all posts
TOP yourself. .
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-21 14:09:01
| Show all posts
Depressed. You also have to ask this question. Then you declare @PublicName.
Reply

Use magic Report

0

Threads

8

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-21 16:54:02
| Show all posts
Oh
Reply

Use magic Report

4

Threads

24

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-1-22 07:45:01
| Show all posts
Declaration @PublicName
Reply

Use magic Report

2

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-1-24 10:18:01
| Show all posts
Halo said for a long time. I just ask how to declare? Where to declare it?
Reply

Use magic Report

0

Threads

58

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-1-24 22:45:01
| Show all posts
DefineTypeDS.Select (new DataSourceSelectArguments ());
Reply

Use magic Report

2

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-1-25 16:45:01
| Show all posts
DefineTypeDS.Select (new DataSourceSelectArguments ());


Not the problem. Tried it. Still wrong.
Reply

Use magic Report

2

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-1-29 20:45:02
| Show all posts
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";

I tried it myself. Just remove the @ in front of @PublicName. do not know why.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list