Calling a Stored procedure
I'm new to C# I need to call a SP and return the table value from C#.
I'm passing current datetime(@currentdate) as my input parameter in the
stored procedure.So how do I pass this in C# method?
Pls help me to write a C# method to call that SP and return the value
I have my sp ready. sp will return the top updated record in the table.
I have used this in my C# code
string _Num = null;
SqlConnection sqlConnection1 = new SqlConnection("Data
Source=localhost;Initial Catalog=ReferenceDB;Persist Security
Info=True;Integrated Security=SSPI");
SqlCommand cmd = new SqlCommand();
Int32 rowsAffected;
Object returnValue;
cmd.CommandText = "Number";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@CurrentDate", DateTime.Now);
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
rowsAffected = cmd.ExecuteNonQuery();
returnValue = cmd.ExecuteScalar();
if (returnValue != null)
_Num = returnValue.ToString();
return _Num
No comments:
Post a Comment