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.........

Why cant u try this:

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

}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.