| |

VerySource

 Forgot password?
 Register
Search
View: 628|Reply: 6

About the use of parameters ~ oledb

[Copy link]

2

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-2-22 14:30:01
| Show all posts |Read mode
Does that older brother have time?
A little question about the use of parameters
I look at msdn and can't understand
  string sql = "select * from members where userName =?";

What does this question mark mean?

What then? How to use Parameters?
I originally wrote this, but it is said that a question mark must be used
string sql = "select * from members where userName = @ name";
What should I write with a question mark?
Reply

Use magic Report

0

Threads

16

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-5-5 19:45:01
| Show all posts
Who told you the question mark must be used? Wasn't your original good?
SqlConnection MyConn = new .........
string sql = "select * from members where userName = @ name";
SqlCommand MyComm = new SqlCommand (sql, MyConn);

MyComm.Parameters.Add ("@ name", SqlDbType.VarChar, 20);
.........
Reply

Use magic Report

2

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-5-9 08:30:01
| Show all posts
Can you help me to see what is wrong in the following paragraph? Report an error at ds.fill
OleDbConnection con = new OleDbConnection ("server = lo; uid = sa; pwd = sa; database = test; Provider = SQLOLEDB");
   string sql = "select * from members where userName = @ userName";
    con.Open ();
    OleDbDataAdapter da = new OleDbDataAdapter (sql, con);
 da.SelectCommand.Parameters.Add ("@ userName", this.TextBox1.Text.Trim ());
  DataSet ds = new DataSet ();
   da.Fill (ds);
  con.Close ();
  this.DataGrid2.DataSource = ds.Tables [0];
  this.DataGrid2.DataBind ();
Reply

Use magic Report

0

Threads

52

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-5-10 10:30:01
| Show all posts
What is wrong?
Reply

Use magic Report

2

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-5-11 16:45:02
| Show all posts
Must declare parameters
But haven't I already declared it?
Reply

Use magic Report

2

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-5-11 20:45:01
| Show all posts
It is said that oledb must use "?" (Question mark), not directly @name
How to write with question mark?
Thank you for your advice, thank you ~
Reply

Use magic Report

2

Threads

11

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-5-14 02:30:02
| Show all posts
I figured it out myself
Hee hee
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