Thursday, 3 August 2017
Multiplication Table
Flow Chart Factorial Number
SQL Server output parameter
Output Parameter
Input parameter
Output Parameter
Advantage
- Decrease complexity because it help you to do more than one task in single procedure
- when inserting data to a table and you need to get the identity value back
- when perfoming select statements and you need some extra data,
- when updating or inserting data and you need some way to know if the operation was successful
- for most if not all of the reasons you need out or ref parameters in c#
Store Procedure
C# Code
UserModel ob = new
UserModel();
try
{
using
(SqlConnection dbCon = new
SqlConnection(ConfigurationManager.ConnectionStrings["dbConnection"].ToString()))
{
using
(SqlCommand cmd = new SqlCommand("[dbo].[pcheck]",
dbCon))
{
cmd.CommandType =
CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id",
Convert.ToInt32(id));
cmd.Parameters.Add("@phone",
SqlDbType.VarChar, 30);
cmd.Parameters["@phone"].Direction
= ParameterDirection.Output;
if
(dbCon.State == ConnectionState.Closed)
dbCon.Open();
cmd.ExecuteNonQuery();
b.MobileNo =
Convert.ToString(cmd.Parameters["@phone"].Value);
}
}
}
catch
(Exception ex)
{
}
return ob;