Stored Procedure without Parameters
1. Use stored procedures in SQL Server
Create procedure [DBO]. [sp_fuck]
As
Select sage, sname, ssex
From students
Order by sage, sname
2. Create a console application project.
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Data;
Using system. Data. sqlclient;
Namespace callsp1
{
Class Program
{
Static void main (string [] ARGs)
{
// Create connection
Sqlconnection conn = new sqlconnection
(@ "Server =./wb_james;
Integrated Security = sspi;
Database = Master"
);
Try
{
Conn. open (); // open connection
Sqlcommand cmd = conn. createcommand (); // CREATE Command;
Cmd. commandtype = commandtype. storedprocedure;
Cmd. commandtext = "sp_fuck ";
Sqldatareader RDR = cmd. executereader (); // Execute Command;
While (RDR. Read ())
{
Console. writeline (
"{0} {1} {2 }"
, RDR [0]. tostring (). padright (5), RDR [1]. tostring (), RDR [2]. tostring ());
}
RDR. Close ();
}
Catch (sqlexception ex)
{
Console. writeline (ex. tostring ());
}
Finally
{
Conn. Close ();
}
}
}
}
Note: This is the students table of the master database on my computer! Other tables are similar