Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How do we use stored procedure in ADO.NET and how do we provide parameters to the stored procedures
How do we use stored procedure in ADO.NET and how do we provide parameters to the stored procedures?
✍: Guest
ADO.NET provides the SqlCommand object which provides the functionality of executing
stored procedures.
Note :- Sample code is provided in folder “WindowsSqlClientCommand”. There are two
stored procedures created in same database “Employees” which was created for the previous
question.
CREATE PROCEDURE SelectByEmployee @FirstName nvarchar(200) AS Select FirstName from Employees where FirstName like @FirstName + '%' CREATE PROCEDURE SelectEmployee AS Select FirstName from Employees If txtEmployeeName.Text.Length = 0 Then objCommand = New SqlCommand(“SelectEmployee”) Else objCommand = New SqlCommand(“SelectByEmployee”) objCommand.Parameters. SqlDbType.NVarChar, 200) objCommand.Parameters. txtEmployeeName.Text.Trim() End If
In the above sample not much has been changed only that the SQL is moved to the stored procedures. There are two stored procedures one is “SelectEmployee” which selects all the employees and the other is “SelectByEmployee” which returns employee name starting with a specific character. As you can see to provide parameters to the stored procedures we are using the parameter object of the command object. In such question interviewer expects two simple answers one is that we use command object to execute stored procedures and the parameter object to provide parameter to the stored procedure. Above sample is provided only for getting the actual feel of it. Be short be nice and get a job.
2007-10-24, 4953👍, 0💬
Popular Posts:
What is CodeDom? “CodeDom” is an object model which represents actually a source code. It is designe...
How To Give a User Read-Only Access to a Database? - MySQL FAQs - Managing User Accounts and Access ...
How To Enter Boolean Values in SQL Statements? - MySQL FAQs - Introduction to SQL Basics If you want...
How Do I Run JUnit Tests from Command Window? To run JUnit tests from a command window, you need to ...
How To Retrieve the Count of Updated Rows? - Oracle DBA FAQ - Working with Database Objects in PL/SQ...