| |

VerySource

 Forgot password?
 Register
Search
View: 977|Reply: 9

What is the difference in the writing of these two types of database query statements?

[Copy link]

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-4 22:30:01
| Show all posts |Read mode
When uploading pictures to the database in binary, I use sql = insert into DD (dd) values ​​('"+ dd +"') "; it cannot be displayed, but I replaced it with sql = insert into DD (dd) values ​​(@dd); It can be displayed normally.
Does the former not support binary uploads? Or any other reason?
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-4 22:33:01
| Show all posts
Never tried this, help you
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-4 22:39:01
| Show all posts
The latter uses stored procedures
Reply

Use magic Report

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-4 23:00:01
| Show all posts
The latter is not a stored procedure, but just a parameter.
Reply

Use magic Report

0

Threads

64

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-1-4 23:42:01
| Show all posts
This is an asp.net forum originally, it is not convenient to discuss in-depth database issues. Your question has something to do with ado.net, just answer it briefly:

Your first way, assuming the syntax is correct, then the compiler first converts the variable bb to a string (using the object's ToString method), and then combines the string into a sql variable. You can set a breakpoint to see what the result of the sql variable is, and see if the command sent to the database is what you mean by submitting binary image data.

In the first way, SQL is not the correct logical meaning at all.

The second method is very standard, and it is clear that ado.net's SQL command parameters are designed in this way, there is nothing to say.
Reply

Use magic Report

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-5 00:24:01
| Show all posts
The variable bb here is of type byte [].
What I want to make sure is: assuming everything is OK, can I upload binary data in the first way?
Reply

Use magic Report

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-5 10:03:01
| Show all posts
top!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-5 18:45:01
| Show all posts
Maybe it's a relationship
Reply

Use magic Report

0

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-3-9 18:15:01
| Show all posts
The first way is to upload binary data. It is not possible. I have used C # to write binary numbers to the database. It must be defined as a binary type. And it cannot be added.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-26 21:30:01
| Show all posts
1. insert into DD (dd) values ​​(""+dd+" ")" is wrong, I am dizzy,,, is a single quote
insert into DD (dd) values ​​("'+dd+"')";
2. The @ in sql=insert into DD (dd) values ​​(@dd) automatically adds single quotes. This is the function of @,
@ Can also be expressed by address, @C:\asdfa.exe is equal to c:\\asdfa.exe
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