DataAccess.CreateCommand C# (CSharp) Method

CreateCommand() private method

private CreateCommand ( string commandText, DbConnection, connection ) : DbCommand
commandText string
connection DbConnection,
return DbCommand
    private DbCommand CreateCommand(string commandText, DbConnection connection)
    {
        DbCommand command = factory.CreateCommand();
        command.Connection = connection;
        command.CommandText = commandText;
        return command;
    }

Usage Example

Esempio n. 1
0
    public static StMDetail SpMDetailGetDataStructById(string detailid)
    {   // get a configured DbCommand object
        DbCommand comm = DataAccess.CreateCommand();

        // set the stored procedure name
        comm.CommandText = "SpMDetailGetDataStructById";

        // create a new parameter
        DbParameter param = comm.CreateParameter();

        param.ParameterName = "@detailid";
        param.Value         = detailid;
        param.DbType        = DbType.Int32;
        comm.Parameters.Add(param);

        //execute procedure and store data in table
        DataTable table = DataAccess.ExecuteSelectCommand(comm);

        //create object of structure
        StMDetail details = new StMDetail();

        //check there is row in table or not
        if (table.Rows.Count > 0)
        {  //create data reader
            DataRow dr = table.Rows[0];

            //store individually each field into object
            details.detailid = Convert.ToInt32(dr["detailid"]);
            details.masterid = Convert.ToInt32(dr["masterid"]);

            details.detail  = dr["detail"].ToString();
            details.date    = dr["date"].ToString();
            details.Yid     = Convert.ToString(dr["YMasterId"]);
            details.Deptid  = Convert.ToString(dr["DepartmentId"]);
            details.StoreId = Convert.ToString(dr["StoreId"]);

            details.BusId      = dr["BusinessId"].ToString();
            details.employeeid = Convert.ToInt32(dr["EmployeeId"]);
            details.userid     = Convert.ToInt32(dr["userid"]);
        }
        //return object with data
        return(details);
    }
All Usage Examples Of DataAccess::CreateCommand