0
cmd=new sqlcommand("insert_student",con)
cmd.commandtype=commandType.StoredProcedure
Add.Parameters.AddwithValue("@stuid",txtstuid.text)
Add.Parameters.AddwithValue("@name",txtname.text)
Add.Parameters.AddwithValue("@course",txtcourse.text)
con.open()
cmd.ExecuteNonQuery()

i want to create method for executing procedure but how it possible...

Function ExecuteStoredProc(Proc as String)
cmd=new sqlcommand(Proc,con)
cmd.commandtype=commandType.StoredProcedure
Add.Parameters.AddwithValue(????,?????)
con.open()
cmd.ExecuteNonQuery()
end function

how to call this function can anybody help me.........

Edited by __avd: Added [code] tags.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by prateekpk5
0

Why cant u try this:

Function ExecuteStoredProcedure(ProcedureName, [parameters separated by comma and a delimiter]){

}

0
public bool ChangePassword(int empId, string oldPwd, string newPwd, out bool success)
        {
            bool _couldSave = false;
            success = false;

            Database dbObj = null;
            DbCommand dbCommand = null;

            dbObj = DatabaseFactory.CreateDatabase();
            dbCommand = dbObj.GetStoredProcCommand("Users_ChangePassword");// passing the Stored Procedure)
            dbObj.AddInParameter(dbCommand, "@intEmpId", DbType.Int32, empId);// passing Parameters to the Stored Proc
            dbObj.AddInParameter(dbCommand, "@chvOldPwd", DbType.String, oldPwd);
            dbObj.AddInParameter(dbCommand, "@chvNewPwd", DbType.String, newPwd);
            dbObj.AddOutParameter(dbCommand, "@bitSuccess", DbType.Boolean, 1);


            try
            {
                dbObj.ExecuteNonQuery(dbCommand);// Execute the Stored Proc
                _couldSave = true;
                success = dbCommand.Parameters["@bitSuccess"].Value is DBNull ? false : Convert.ToBoolean(dbCommand.Parameters["@bitSuccess"].Value);
            }
            catch (SqlException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }


            return _couldSave;

this the code which i have used for clling the Stored Proc in My application Hope it will help u
Thanks and Regards
Prateek Kulkarni

Edited by __avd: Added [code] tags. Do wrap your programming code blocks within [code] ... [/code] tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.