Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
what is the use of "CommandType.Text?"

Is it necessary to use the cmd.CommandType = CommandType.Text;

What I have tried:

cmd.CommandType = CommandType.Text;
Posted
Updated 24-May-17 1:21am
Comments
ZurdoDev 24-May-17 7:22am    
And along with Solution 1, this is something that is very easily found by searching google. You'll learn much more if you take just a minute to learn things on your own rather than asking simple questions.
Member 13188865 24-May-17 7:38am    
dear ryan, for a science student H2O is water and can be understood easily. But for beginners it gets difficulty in understanding.
Anyway, i have searched for answers for 3 hrs. Althogh got some clarifications, but didn't satisfied me clearly. 'cos i wanted to learn why it is necessary to add it. As my code is running well without using it.

The Text commandtype is used when the command is raw SQL, like "select field from table where id=1". This is the default value of CommandType so if your command is indeed sql then you don't need to set CommandType to text, but it's probably better that you do for clarity (and in case they change the default). If you wwant to set the command to the name of a Stored Procedure or table then you have to specify the correct CommandType.
 
Share this answer
 
Comments
Member 13188865 24-May-17 7:45am    
thx for clarifying, actually i was wondering whether it is necesssary to use it, as my code was running perfectly without using it.
Maciej Los 24-May-17 8:06am    
Please, read my anser. As i mentioned there CommandType default value is Text ;)
Maciej Los 24-May-17 8:07am    
Nice, 5!
Simple. CommandType[^] indicates or specifies how the CommandText property is interpreted.
There are 4 members of CommandType Enumeration[^]
StoredProcedure - The name of a stored procedure.
TableDirect - The name of a table.
Text - An SQL text command. (Default.)

Cocnlusion: you should use CommandType.Text when you want to execute one of CRUD[^] operation.

That's all!
 
Share this answer
 
Comments
Member 13188865 24-May-17 7:46am    
thx for the answer.
Maciej Los 24-May-17 8:05am    
You're very welcome. If it was helpful, you can accept it (green button).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900